sh Test Multiple Expressions


Example

Though it is an obsoleted part of the XSI standard, many implementations still support multiple expressions with Boolean operators and parenthesis.

The (obsolete) operators are listed below with decreasing precedence.

( expression )
expression -a expression
expression -o expression

Using these (obsolete) operators, a complex shell expression:

if [ "$a" -gt 0 ] && { [ "$b" -ne 2 ] || [ "$b" -e 0 ]; }
then ...
fi

Could be written with one invocation of test(1):

if [ "$a" -gt 0 -a '(' "$b" -ne 2 -o "$c" -ne 0 ')' ]
then ...
fi