test(1)
_________________________________________________________________
test Command
condition evaluation command
_________________________________________________________________
SYNTAX
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 also returns a non-zero exit status
if there are no arguments. The following primitives are used to
construct expr:
-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.
-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.
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
test(1)
-n s1 True if the length of the string s1 is non-zero.
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.
n1 -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 in place of -eq.
You can combine these primaries 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.
All the operators and flags are separate arguments to test.
Parentheses are meaningful to the shell and, therefore, must be
escaped.
_________________________________________________________________
EXAMPLES
$ test -r exercise.1
Tests the expression "-r exercise.1". Checks if the file
"exercise.1" exists and is readable. If it exists and is
readable, then test sets the exit status to zero.
$ [ "$a" = "yes" ]
Checks if the value for the variable "a" is the string "yes". If
it is test sets the exit status to zero. Note that the square
brackets must be delimited by blanks for this form of test to
work.
$ if
test -s exercise.1
then
pr exercise.1
fi
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
test(1)
This is an example of using test in a shell program. The test in
this shell program tests the expression "-s exercise.1", which
checks if "exercise.1" is a file with at lease one character. If
"exercise.1" is a file and has at least one character, the
program prints the file. Otherwise, the program does not print
"exercise.1."
_________________________________________________________________
SEE ALSO
find(1), sh(1).
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.
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)