Test

Other topics

Multiple Expressions

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

Syntax:

  • test
  • test [!] [ -n | -z ] string
  • test [!] { -b | -c | -d | -e | -f | -g | -h | -L | -p | -r | -S | -s | -u | -w | -x } file
  • test [!] -t fd
  • test [!] string { = | != } string
  • test [!] integer { -eq | -ne | -gt | -ge | -lt | -le } integer
  • [ ]
  • [ [!] [ -n | -z ] string ]
  • [ [!] { -b | -c | -d | -e | -f | -g | -h | -L | -p | -r | -S | -s | -u | -w | -x } file ]
  • [ [!] -t fd ]
  • [ [!] string { = | != } string ]
  • [ [!] integer { -eq | -ne | -gt | -ge | -lt | -le } integer ]

Contributors

Topic Id: 7683

Example Ids: 25229

This site is not affiliated with any of the contributors.