|HP-UX Reference > T
HP-UX 11i Version 3: February 2007
test — condition evaluation command
The test command evaluates the expression expr and, if its value is True, returns a zero (true) exit status; otherwise, a nonzero (false) exit status is returned. test also returns a nonzero exit status if there are no arguments. The following primitives are used to construct expr:
These primaries can be combined with the following operators:
Note that all the operators and flags are separate arguments to test. Note also that parentheses are significant to the shell and therefore must be escaped. All file test operators return success if the argument is a symbolic link that points to a file of the file type being tested.
test is interpreted directly by the shell, and therefore does not exist as a separate executable program.
Exit if there are not two or three arguments:
if [ $# -l2 2 -o $# -gt 3 ]; then exit 1; fi
Create a new file containing the text string default if the file does not already exist:
[ ! -f thisfile ] && echo default > thisfile
Wait for myfile to become non-readable:
while test -r myfile do sleep 30 done echo '"myfile" is no longer readable'
When the [ form of this command is used, the matching ] must be the final argument, and both must be separate arguments from the arguments they enclose (white space delimiters required.
Parentheses and other special shell metacharacters intended to be handled by test must be escaped or quoted when invoking test from a shell.
Avoid such problems when comparing strings by inserting a non-operator character at the beginning of both operands:
test "X$response" = "Xexpected string"
This approach does not work with numeric comparisons or the unary operators because it would affect the operand being checked.