I’ve just found the following code in a ksh script:
if [ "${file_id}" = "0" ] || [ "${file_id}" = "100" ] || "${file_id}" = "100" ]
then
# Do some stuff
fi
Note, in particular, the missing [ before the third ${file_id}.
I’m happy that this isn’t very pleasant syntax, even without that error, and that [[ … ]] is generally preferable to [ … ] in ksh.
However, this code runs entirely as desired, and ksh -n doesn’t object to the above at all. Why doesn’t the above fail?
if [ "${file_id}" = "0" ] || [ "${file_id}" = "100" ] || "${file_id}" = "100" ]This command exicuted from Left to Right. If this command found the value of
file_idis0then it will not check for the next conditions because, these conditions are separated with theoroperator. If both 1st and 2nd conditions will not satisfied then it will try to check for the 3rd condition and it will be failed.