&&
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.
! [[ $1 = foo || $1 = bar ]]
Rare.
if [[ $FOO != $BAR || $FOO != $COW ]] then echo "$FOO and $BAR and $COW are not all equal" fi
There was an error while loading. Please reload this page.