HP-UX Reference (11i v1 05/09) - 1 User Commands N-Z (vol 2)
t
test(1) test(1)
EXAMPLES
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’
WARNINGS
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.
AUTHOR
test was developed by the University of California, Berkeley and HP.
SEE ALSO
find(1), sh-bourne(1), sh-posix(1), sh(1).
STANDARDS CONFORMANCE
test: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
[: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
Section 1−−976 Hewlett-Packard Company − 2 − HP-UX 11i Version 1: September 2005