'\"macro stdmacro
.if n .pH g1.test @(#)test	41.2 of 12/29/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} test 1 "Essential Utilities" "\&"
.if \nX=1 .ds x} test 1 "Essential Utilities"
.if \nX=2 .ds x} test 1 "" "\&"
.if \nX=3 .ds x} test "" "" "\&"
.TH \*(x}
.\" @(#)test.1 1.3 88/10/17 SMI;
.\" Copyright (c) 1988 Sun Microsystems, Inc - All Rights Reserved.
.SH NAME
\f4test\f1 \- condition evaluation command
.SH SYNOPSIS
\f4test \f2expr\f1
.br
[\f2expr\f1]
.SH DESCRIPTION
\f4test\fP
evaluates the expression
\f2expr\fP
and, if its value is true, sets a zero (true) exit status; otherwise, a
non-zero (false) exit status is set;
\f4test\fP
also
sets a non-zero exit status if there are no arguments.
When permissions are tested,
the effective user \s-1ID\s0 of the process is used.
.PP
All operators, flags, and brackets
(brackets used as shown in the second \s-1SYNOPSIS\s0 line)
must be separate arguments to the
\f4test\fP
command;
normally these items are separated by spaces.
.PP
The following primitives are used to construct
\f2expr\fP:
.TP 12
\f4\-r\f2 file\^\f1
true if \f2file\f1 exists and is readable.
.TP
\f4\-w\f2 file\^\f1
true if \f2file\f1 exists and is writable.
.TP
\f4\-x\f2 file\^\f1
true if
.I file\^
exists and is executable.
.TP
\f4\-f\f2 file\^\f1
true if \f2file\f1 exists and is a regular file.
Alternatively, if
\f4/usr/sh\f1
users specify
\f4/usr/ucb\f1
before
\f4/usr/bin\f1
in their
.SM PATH
environment variable, then
\f4test\fP
will return true if
.I file
exists and is
\f1(\f4not\-a\-directory\f1).
This is also the default for
\f4/usr/bin/csh\f1
users.
.TP
\f4\-d\f2 file\^\f1
true if \f2file\f1 exists and is a directory.
.TP 
\f4\-h\f2 file\^\f1
true if \f2file\f1 exists and is a symbolic link. With all other
primitives (except \f4\-L\f2 file\f1),
the symbolic links are followed by default.
.TP
\f4\-c\f2 file\^\f1
true
if
.I file\^
exists and is a character special file.
.TP
\f4\-b\f2 file\^\f1
true if
.I file\^
exists and is a block special file.
.TP
\f4\-p\f2 file\^\f1
true if
.I file\^
exists and is a named pipe (fifo).
.TP
\f4\-u\f2 file\^\f1
true if
.I file\^
exists and its set-user-\c
.SM ID
bit is set.
.TP
\f4\-g\f2 file\^\f1
true if
.I file\^
exists and its set-group-\c
.SM ID
bit is set.
.TP
\f4\-k\f2 file\^\f1
true if
.I file\^
exists and its sticky bit is set.
.TP
\f4\-s\f2 file\^\f1
true if \f2file\f1 exists and has a size greater than zero.
.TP
\f4\-t\f1 [ \f2fildes\f1 ]
true if the open file whose file descriptor number is
.I fildes\^
(1 by default)
is associated with a terminal device.
.TP
\f4\-z\f2 s1\^\f1
true if the length of string
.I s1\^
is zero.
.TP
\f4\-n\f2 s1\^\f1
true if the length of the string
.I s1\^
is non-zero.
.TP
\f2s1\f4 = \f2s2\^\f1
true
if strings
.I s1\^
and
.I s2\^
are identical.
.TP
\f2s1\f4 != \f2s2\^\f1
true
if strings
.I s1\^
and
.I s2\^
are
.I not\^
identical.
.TP
.I s1\^
true if
.I s1\^
is
.I not\^
the null string.
.TP
\f2n1\f4 \-eq \f2n2\^\f1
true if the integers
.I n1\^
and
.I n2\^
are algebraically equal.
Any of the comparisons
\f4\-ne\f1,
\f4\-gt\f1,
\f4\-ge\f1,
\f4\-lt\f1,
and
\f4\-le\f1
may be used in place of
\f4\-eq\f1.
.TP 
\f4\-L\f2 file\^\f1
true if \f2file\f1 exists and is a symbolic link. With all other
primitives (except \f4\-h\f2 file\f1),
the symbolic links are followed by default.
.br
.ne 6
.PP
These primaries may be combined with the
following operators:
.TP  12
\f4 !\f1
unary negation operator.
.TP
\f4 \-a\f1
binary
.I and\^
operator.
.TP
\f4 \-o\f1
binary
.I or\^
operator
\f1(\f4\-a\f1
has higher precedence than
\f4\-o\f1).
.TP
(\f2expr\f1)
parentheses for grouping.
Notice also that parentheses are meaningful
to the shell and, therefore, must be quoted.
.SH "SEE ALSO"
\f4find\fP(1), \f4sh\fP(1).
.br
.ne 4v
.SH NOTES
.PP
The \f4not\-a\-directory\f1 alternative to the
\f4\-f\f1
option is a transition aid for
.SM BSD
applications and may not be supported in future releases.
.PP
The
\f4\-L\f1
option is a migration aid for users of other shells
which have similar options and may not be supported in
future releases.
.PP
If you test a file you own
(the
.IR -r ,
.IR -w ,
or
.I -x\^
tests),
but the permission tested does not have the
.I owner\^
bit set,
a non-zero (false) exit status will be returned
even though the file may have the
\f4group\fP
or
.I other\^
bit set for that permission.
The correct exit status will be set if you are
super-user.
.PP
The
\f4=\f1
and
\f4!=\f1
operators have a higher precedence than the
\f4\-r\f1
through
\f4\-n\f1
operators,
and
\f4=\f1
and
\f4!=\f1
always expect arguments;
therefore,
\f4=\f1
and
\f4!=\f1
cannot be used with the
\f4\-r\f1
through
\f4\-n\f1
operators.
.PP
If more than one argument follows the
\f4\-r\f1
through
\f4\-n\f1
operators,
only the first argument is examined;
the others are ignored,
unless a
\f4\-a\f1
or a
\f4\-o\f1
is the second argument.
.\"	@(#)test.1	6.2 of 9/2/83
.Ee
