&&
if [ "$1" != foo ] || [ "$1" != bar ] then echo "$1 is not foo or bar" fi
if [ "$1" != foo ] && [ "$1" != bar ] then echo "$1 is not foo or bar" fi
This is not a bash issue, but a simple, common logical mistake applicable to all languages.
[ "$1" != foo ] || [ "$1" != bar ] is always true (when foo != bar):
[ "$1" != foo ] || [ "$1" != bar ]
foo != bar
$1 = foo
$1 != bar
$1 = bar
$1 != foo
$1 = cow
[ $1 != foo ] && [ $1 != bar ] matches when $1 is neither foo nor bar:
[ $1 != foo ] && [ $1 != bar ]
$1
foo
bar
This statement is identical to ! [ "$1" = foo ] || [ "$1" = bar ], which also works correctly (by De Morgan's law)
! [ "$1" = foo ] || [ "$1" = bar ]
This warning is equivalent to SC2055 and SC2056, which trigger for intra-test expressions and arithmetic contexts respectively.
test
Rare.
There was an error while loading. Please reload this page.