TEST(1) User Commands TEST(1)

test - condition command

test [expr]

test evaluates the expression expr, and if its value is true then returns zero exit status; otherwise, a non zero exit status is returned. test returns a non zero exit if there are no arguments.

The following primitives are used to construct expr:

true if the file exists and is readable.
true if the file exists and is writable.
true if the file exists and has the setuid bit set.
true if the file exists and has the setgid bit set.
true if the file exists and has the sticky bit set.
true if the file exists and is a regular file.
true if the file exists and is a directory.
true if the file exists and is a symbolic link.
true if the file exists and is a symbolic link.
true if the file exists and is a named pipe.
true if the file exists and is a block device.
true if the file exists and is a character device.
true if the file exists and is a socket (/usr/5bin/posix/test and /usr/5bin/posix2001/test only).
true if the file exists (/usr/5bin/posix/test and /usr/5bin/posix2001/test only).
true if the file exists and has a size greater than zero.
true if the open file whose file descriptor number is fildes (1 by default) is associated with a terminal device.
true if the length of string s1 is zero.
true if the length of the string s1 is nonzero.
s1 = s2
true if the strings s1 and s2 are equal.
s1 != s2
true if the strings s1 and s2 are not equal.
true if s1 is not the null string.
n1 -eq n2
true if the integers n1 and n2 are algebraically equal. Any of the comparisons -ne, -gt, -ge, -lt, or -le may be used in place of -eq.

These primaries may be combined with the following operators:

!
unary negation operator
binary and operator
binary or operator
( expr )
parentheses for grouping.

-a has higher precedence than -o. Notice that all the operators and flags are separate arguments to test. Notice also that parentheses are meaningful as command separators and must be escaped.

7/2/05 Heirloom Toolchest