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:
[[ $1 != foo || $1 != bar ]]
$1 = foo
$1 != bar
$1 = bar
$1 != foo
$1 = cow
[[ $1 != foo && $1 != bar ]] matches when $1 is not foo and not 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 ]]
None.
There was an error while loading. Please reload this page.