test(1) DG/UX 4.30 test(1)
NAME
test - condition evaluation command
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 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.
-% file True if file exists and is a control point
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.
-h 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.
Licensed material--property of copyright holder(s) Page 1
test(1) DG/UX 4.30 test(1)
-z s1 True if the length of string s1 is zero.
-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
This is an example of using test in a shell program. The
Licensed material--property of copyright holder(s) Page 2
test(1) DG/UX 4.30 test(1)
test in this shell program tests the expression -s
exercise.1, which checks if exercise.1 is a file with at
least 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.
Licensed material--property of copyright holder(s) Page 3