Compound ‘if’ statements with multiple expressions in Bash

For Bash, you can use the [[ ]] form rather than [ ], which allows && and || internally:

if [[ foo || bar || baz ]] ; then
  ...
fi

Otherwise, you can use the usual Boolean logic operators externally:

[ foo ] || [ bar ] || [ baz ]

…or use operators specific to the test command (though modern versions of the POSIX specification describe this XSI extension as deprecated — see the APPLICATION USAGE section):

[ foo -o bar -o baz ]

…which is a differently written form of the following, which is similarly deprecated:

test foo -o bar -o baz

Leave a Comment