I am trying to check if the the variable $userSelection is not having value 1, 2 or 3, then I display error message. Tried the following and other combinations, but no luck.
if [ $userSelection -ne 1 || $userSelection -ne 2 ] || [ $userSelection -ne 2 || $userSelection -ne 3 ]
then
echo "Option selected not valid...please try again."
fi
Am getting error [: missing]'`.
[ $userSelection -ne 2Easy to miss with all those bars.[is a command. It has the odd behavior of requiring that its last argument be]. You are trying to run the command[ $userSelection -ne 1and then (if it is successful) the command$userSelection -ne 2. You must stop thinking of[as being a symbol in the grammar of the shell. It is just a command. This is often more clear if you spell ittest(which is exactly the same as[, except that it does not require that its final argument be])[is necessary to start a new command, because[doesn't support||. He's actually missing quite a few brackets.