(coreutils.info)Connectives for test


Prev: Numeric tests Up: test invocation
Enter node , (file) or (file)node

16.3.6 Connectives for ‘test’
-----------------------------

Note it’s preferred to use shell logical primitives rather than these
logical connectives internal to ‘test’, because an expression may become
ambiguous depending on the expansion of its parameters.

   For example, this becomes ambiguous when ‘$1’ is set to ‘'!'’ and
‘$2’ to the empty string ‘''’:

     test "$1" -a "$2"

   and should be written as:

     test "$1" && test "$2"

   Note the shell logical primitives also benefit from short circuit
operation, which can be significant for file attribute tests.

‘! EXPR’
     True if EXPR is false.  ‘!’ has lower precedence than all parts of
     EXPR.  Note ‘!’ needs to be specified to the left of a binary
     expression, I.e., ‘'!' 1 -gt 2’ rather than ‘1 '!' -gt 2’.  Also
     ‘!’ is often a shell special character and is best used quoted.

‘EXPR1 -a EXPR2’
     True if both EXPR1 and EXPR2 are true.  ‘-a’ is left associative,
     and has a higher precedence than ‘-o’.

‘EXPR1 -o EXPR2’
     True if either EXPR1 or EXPR2 is true.  ‘-o’ is left associative.


automatically generated by info2www version 1.2.2.9