| Text-only | Table of Contents (frame/ no frame) |
| (16) Conditional Tests |
|
test
command, or its alias, [, or the ksh/bash built-in [[ ... ]]
command, which has slightly different options, or it can be any command which returns
a suitable exit status. Zero is taken to be "True", while any non-zero value is "False".
Note that this is backwards from the C language convention.
-e file
-f file
-d file
-r file
-w = writable, -x = executable, -L = is a symlink.
-s file
-t filedescriptor
-n "string"
-z "string"
With[, the argument must be quoted, because if it is a variable that has a null value, the resulting expansion ( [ -z ] ) is a syntax error. An expansion resulting in "" counts as a null string.
For[only, a quoted string alone is equivalent to the -n test, e.g. [ "$var" ]. In older shells for which[is an external program, the only way to test for a null string is:
if [ "X$var" = "X" ]
This is rarely needed now, but is still often found.
$variable = text
$variable < text
> = comes after
| cond-tests.src last modified Feb 11, 2005 | Introduction | Table of Contents (frame/no frame) |
Printable (single file) |
© Dartmouth College |