manpagez: man pages & more
info coreutils
Home | html | info | man

File: coreutils.info,  Node: Connectives for test,  Prev: Numeric tests,  Up: test invocation

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.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.