TEST(1V) — USER COMMANDS
NAME
test, − test a condition
SYNOPSIS
test expr
[ expr ]
DESCRIPTION
test evaluates the expression expr and, if its value is true, returns a zero (true) exit status; otherwise, a non-zero (false) exit status is returned. test returns a non-zero exit if there are no arguments.
The following primitives are used to construct expr.
−b file true if file exists and is a block special device.
−c file true if file exists and is a character special device.
−d file true if file exists exists and is a directory.
−f file true if file exists and is not a directory.
−g file true if file exists and its set-group- ID bit is set.
−h file true if file exists and is a symbolic link.
−k file true if file exists and its sticky bit is set.
−l string the length of the string.
−n s1 true if the length of the string s1 is non-zero.
−p file true if file exists and is a named pipe (fifo).
−r file true if file exists and is readable.
−s file true if file exists and has a size greater than zero.
−t [ fildes ]
true if the open file whose file descriptor number is fildes (1 by default) is associated with a terminal device.
−u file true if file exists and its set-user- ID bit is set.
−w file true if file exists and is writable.
−x file true if file exists and is executable.
−z s1 true if the length of string s1 is zero.
s1 = s2 true if the strings s1 and s2 are equal.
s1 != s2 true if the strings s1 and s2 are not equal.
s1 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
−a binary and operator
−o 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 to the Shell and must be escaped.
SYSTEM V DESCRIPTION
The actions of the System V version of test are the same, except for the following primitives:
−f file true if file exists and is a regular file.
−l string not supported.
NOTE
The test command is built into the shell. The shell chooses the 4.2BSD or the System V version of test depending on whether /usr/5bin appears before /bin in the shell’s PATH variable, just as the 4.2BSD or System V versions of regular commands are selected depending on whether /usr/5bin appears before the directory in which the 4.2BSD version of that command appears.
The fact that test is built into the shell also means that a program named test cannot be run without specifying a pathname; if the program is in the current directory, ./test will suffice.
SEE ALSO
WARNING
In the second form of the command (i.e., the one that uses [], rather than the word test), the square brackets must be delimited by blanks.
Some UNIX systems do not recognize the second form of the command.
Sun Release 3.2 — Last change: 1 May 1986