test(1) CLIX test(1)
NAME
test - Condition evaluation command
SYNOPSIS
test expr
[expr]
FLAGS
-r file True if file exists and is readable.
-w file True if file exists and is writable.
-x file True if file exists and is executable.
-f file True if file exists and is a regular file.
-d file True if file exists and is a directory.
-c file True if file exists and is a character special file.
-b file True if file exists and is a block special file.
-L file True if file exists and is a symbolic link.
-p file True if file exists and is a named pipe (fifo).
-u file True if file exists and its set-user-ID bit is set.
-g file True if file exists and its set-group-ID bit is set.
-k file True if file exists and its sticky bit is set.
-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.
-z s1 True if the length of string s1 is zero.
-n s1 True if the length of the string s1 is nonzero.
s1 = s2 True if strings s1 and s2 are identical.
s1 != s2 True if strings s1 and s2 are not identical.
s1 True if s1 is not the null string.
2/94 - Intergraph Corporation 1
test(1) CLIX test(1)
nl -eq n2 True if the integers n1 and n2 are algebraically equal. Any
of the comparisons -ne, -gt, -ge, -lt, and -le may be used
instead of -eq.
The primary flags above may be combined with the following operators:
! Unary negation operator.
-a Binary AND operator.
-o Binary OR operator (-a has higher precedence than -o).
( expr ) Parentheses for grouping. Notice also that parentheses are
meaningful to the shell. Therefore, they must be quoted.
DESCRIPTION
The test command evaluates the expression expr and, if its value is true,
sets a zero (true) exit status; otherwise, a nonzero (false) exit status
is set. The test command also sets a nonzero exit status if there are no
arguments. When permissions are tested, the effective process user ID is
used.
EXAMPLES
1. To test whether there is a file called /tmp/lake, enter the following:
-f /tmp/lake
The test command returns 0 if the file /tmp/lake exists.
2. If you enter this command line, the test command returns a 1 because
``foo'' is not equal to ``fred''.
test "foo" = "fred"
CAUTIONS
If an owned file is tested (the -r, -w, or -x tests), but the permission
tested does not have the owner bit set, a nonzero (false) exit status will
be returned even though the file may have the group or other bit set for
that permission. The correct exit status will be set if executed by the
superuser.
The = and != operators have a higher precedence than the -r through -n
operators, and = and != always expect arguments; therefore, = and !=
cannot be used with the -r through -n operators.
If more than one argument follows the -r through -n operators, only the
first argument is examined; the others are ignored unless -a or -o is the
2 Intergraph Corporation - 2/94
test(1) CLIX test(1)
second argument.
EXIT VALUES
The test command exits with a value of 0 if true and 1 if false.
RELATED INFORMATION
Commands: find(1), sh(1)
2/94 - Intergraph Corporation 3