I have a code bit like this which works just fine;
if [ "$1" == "something1" ] || [ "$1" == "something2" ] || [ "$1" == "something3" ]; then
echo "Result is $1"
# do stuff here if $1 is not equals to one of the above "somethings"
fi
$ ./script.sh something2
Result is something2
However, when I change the equal operators (==
) into not equals (!=
) then it simply doesn't work anymore.
Example:
if [ "$1" != "something1" ] || [ "$1" != "something2" ] || [ "$1" != "something3" ]; then
echo "Result is $1"
# do stuff here if $1 is not equals to one of the above "somethings"
fi
$ ./script.sh something2
Result is something2
It shouldn't have print out the Result is something2
. I added this to my bash script #!/bin/bash -x
to see the problem and it says + [[ something2 != something1 ]]
when I run the script as ./script.sh something2
so definitely something's wrong here.
I basically want it to continue the if statement if the $1
is not equals to one of the somethings
otherwise skip.
What am I missing?