The application shall ensure that all operators and elements of
primaries are presented as separate arguments to the test
utility.
The following primaries can be used to construct expression:
-b
pathname
True if pathname resolves to an existing directory
entry for a block special file. False if pathname
cannot be resolved, or if pathname resolves to an
existing directory entry for a file that is not a block
special file.
-c
pathname
True if pathname resolves to an existing directory
entry for a character special file. False if pathname
cannot be resolved, or if pathname resolves to an
existing directory entry for a file that is not a
character special file.
-d
pathname
True if pathname resolves to an existing directory
entry for a directory. False if pathname cannot be
resolved, or if pathname resolves to an existing
directory entry for a file that is not a directory.
-e
pathname
True if pathname resolves to an existing directory
entry. False if pathname cannot be resolved.
-f
pathname
True if pathname resolves to an existing directory
entry for a regular file. False if pathname cannot be
resolved, or if pathname resolves to an existing
directory entry for a file that is not a regular file.
-g
pathname
True if pathname resolves to an existing directory
entry for a file that has its set-group-ID flag set.
False if pathname cannot be resolved, or if pathname
resolves to an existing directory entry for a file that
does not have its set-group-ID flag set.
-h
pathname
True if pathname resolves to an existing directory
entry for a symbolic link. False if pathname cannot be
resolved, or if pathname resolves to an existing
directory entry for a file that is not a symbolic link.
If the final component of pathname is a symbolic link,
that symbolic link is not followed.
-L
pathname
True if pathname resolves to an existing directory
entry for a symbolic link. False if pathname cannot be
resolved, or if pathname resolves to an existing
directory entry for a file that is not a symbolic link.
If the final component of pathname is a symbolic link,
that symbolic link is not followed.
-n
string True if the length of string is non-zero; otherwise,
false.
-p
pathname
True if pathname resolves to an existing directory
entry for a FIFO. False if pathname cannot be resolved,
or if pathname resolves to an existing directory entry
for a file that is not a FIFO.
-r
pathname
True if pathname resolves to an existing directory
entry for a file for which permission to read from the
file will be granted, as defined in Section 1.1.1.4,
File Read, Write, and Creation. False if pathname
cannot be resolved, or if pathname resolves to an
existing directory entry for a file for which
permission to read from the file will not be granted.
-S
pathname
True if pathname resolves to an existing directory
entry for a socket. False if pathname cannot be
resolved, or if pathname resolves to an existing
directory entry for a file that is not a socket.
-s
pathname
True if pathname resolves to an existing directory
entry for a file that has a size greater than zero.
False if pathname cannot be resolved, or if pathname
resolves to an existing directory entry for a file that
does not have a size greater than zero.
-t
file_descriptor
True if file descriptor number file_descriptor is open
and is associated with a terminal. False if
file_descriptor is not a valid file descriptor number,
or if file descriptor number file_descriptor is not
open, or if it is open but is not associated with a
terminal.
-u
pathname
True if pathname resolves to an existing directory
entry for a file that has its set-user-ID flag set.
False if pathname cannot be resolved, or if pathname
resolves to an existing directory entry for a file that
does not have its set-user-ID flag set.
-w
pathname
True if pathname resolves to an existing directory
entry for a file for which permission to write to the
file will be granted, as defined in Section 1.1.1.4,
File Read, Write, and Creation. False if pathname
cannot be resolved, or if pathname resolves to an
existing directory entry for a file for which
permission to write to the file will not be granted.
-x
pathname
True if pathname resolves to an existing directory
entry for a file for which permission to execute the
file (or search it, if it is a directory) will be
granted, as defined in Section 1.1.1.4, File Read,
Write, and Creation. False if pathname cannot be
resolved, or if pathname resolves to an existing
directory entry for a file for which permission to
execute (or search) the file will not be granted.
-z
string True if the length of string string is zero; otherwise,
false.
string True if the string string is not the null string;
otherwise, false.
s1 =
s2 True if the strings s1 and s2 are identical; otherwise,
false.
s1 !=
s2 True if the strings s1 and s2 are not identical;
otherwise, false.
n1 -eq
n2 True if the integers n1 and n2 are algebraically equal;
otherwise, false.
n1 -ne
n2 True if the integers n1 and n2 are not algebraically
equal; otherwise, false.
n1 -gt
n2 True if the integer n1 is algebraically greater than
the integer n2; otherwise, false.
n1 -ge
n2 True if the integer n1 is algebraically greater than or
equal to the integer n2; otherwise, false.
n1 -lt
n2 True if the integer n1 is algebraically less than the
integer n2; otherwise, false.
n1 -le
n2 True if the integer n1 is algebraically less than or
equal to the integer n2; otherwise, false.
expression1 -a
expression2
True if both expression1 and expression2 are true;
otherwise, false. The -a
binary primary is left
associative. It has a higher precedence than -o
.
expression1 -o
expression2
True if either expression1 or expression2 is true;
otherwise, false. The -o
binary primary is left
associative.
With the exception of the -h
pathname and -L
pathname primaries,
if a pathname argument is a symbolic link, test shall evaluate
the expression by resolving the symbolic link and using the file
referenced by the link.
These primaries can be combined with the following operators:
!
expression
True if expression is false. False if expression is
true.
(
expression )
True if expression is true. False if expression is
false. The parentheses can be used to alter the normal
precedence and associativity.
The primaries with two elements of the form:
-primary_operator primary_operand
are known as unary primaries. The primaries with three elements
in either of the two forms:
primary_operand -primary_operator primary_operand
primary_operand primary_operator primary_operand
are known as binary primaries. Additional implementation-defined
operators and primary_operators may be provided by
implementations. They shall be of the form -operator where the
first character of operator is not a digit.
The algorithm for determining the precedence of the operators and
the return value that shall be generated is based on the number
of arguments presented to test. (However, when using the "[...]"
form, the <right-square-bracket> final argument shall not be
counted in this algorithm.)
In the following list, $1, $2, $3, and $4 represent the arguments
presented to test:
0 arguments:
Exit false (1).
1 argument: Exit true (0) if $1 is not null; otherwise, exit
false.
2 arguments:
* If $1 is '!'
, exit true if $2 is null, false if
$2 is not null.
* If $1 is a unary primary, exit true if the unary
test is true, false if the unary test is false.
* Otherwise, produce unspecified results.
3 arguments:
* If $2 is a binary primary, perform the binary
test of $1 and $3.
* If $1 is '!'
, negate the two-argument test of $2
and $3.
* If $1 is '('
and $3 is ')'
, perform the unary
test of $2. On systems that do not support the
XSI option, the results are unspecified if $1 is
'('
and $3 is ')'
.
* Otherwise, produce unspecified results.
4 arguments:
* If $1 is '!'
, negate the three-argument test of
$2, $3, and $4.
* If $1 is '('
and $4 is ')'
, perform the two-
argument test of $2 and $3. On systems that do
not support the XSI option, the results are
unspecified if $1 is '('
and $4 is ')'
.
* Otherwise, the results are unspecified.
>4 arguments:
The results are unspecified.
On XSI-conformant systems, combinations of primaries
and operators shall be evaluated using the precedence
and associativity rules described previously. In
addition, the string comparison binary primaries '='
and "!="
shall have a higher precedence than any
unary primary.