250 lines
3.9 KiB
Groff
250 lines
3.9 KiB
Groff
'\"macro stdmacro
|
|
.if n .pH g1.test @(#)test 30.4 of 3/22/86
|
|
.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}
|
|
.SH NAME
|
|
test \- condition evaluation command
|
|
.SH SYNOPSIS
|
|
.B test
|
|
expr
|
|
.br
|
|
.B [
|
|
expr
|
|
.B ]
|
|
.SH DESCRIPTION
|
|
.I test\^
|
|
evaluates the expression
|
|
.I expr\^
|
|
and, if its value is true, sets a zero (true) exit status; otherwise, a
|
|
non-zero (false) exit status is set;
|
|
.I test\^
|
|
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
|
|
.I test
|
|
command;
|
|
normally these items are separated by spaces.
|
|
.PP
|
|
The following primitives are used to construct
|
|
.IR expr :
|
|
.TP 12
|
|
.BI \-r " file\^"
|
|
true if \f2file\f1 exists and is readable.
|
|
.TP
|
|
.BI \-l " file\^"
|
|
true if
|
|
.I file
|
|
exists and is a symbolic link.
|
|
.TP
|
|
.BI \-w " file\^"
|
|
true if \f2file\f1 exists and is writable.
|
|
.TP
|
|
.BI \-x " file\^"
|
|
true if
|
|
.I file\^
|
|
exists and is executable.
|
|
.TP
|
|
.BI \-f " file\^"
|
|
true if \f2file\f1 exists and is a regular file.
|
|
.TP
|
|
.BI \-d " file\^"
|
|
true if \f2file\f1 exists and is a directory.
|
|
.TP
|
|
.BI \-h " file\^"
|
|
true if \f2file\f1 exists and is a symbolic link.
|
|
.TP
|
|
.BI \-c " file\^"
|
|
true
|
|
if
|
|
.I file\^
|
|
exists and is a character special file.
|
|
.TP
|
|
.BI \-b " file\^"
|
|
true if
|
|
.I file\^
|
|
exists and is a block special file.
|
|
.TP
|
|
.BI \-p " file\^"
|
|
true if
|
|
.I file\^
|
|
exists and is a named pipe (fifo).
|
|
.TP
|
|
.BI \-u " file\^"
|
|
true if
|
|
.I file\^
|
|
exists and its set-user-\c
|
|
.SM ID
|
|
bit is set.
|
|
.TP
|
|
.BI \-g " file\^"
|
|
true if
|
|
.I file\^
|
|
exists and its set-group-\c
|
|
.SM ID
|
|
bit is set.
|
|
.TP
|
|
.BI \-k " file\^"
|
|
true if
|
|
.I file\^
|
|
exists and its sticky bit is set.
|
|
.TP
|
|
.BI \-s " file\^"
|
|
true if \f2file\f1 exists and has a size greater than zero.
|
|
.TP
|
|
.BR \-t " [ \f2fildes\f1 ]"
|
|
true if the open file whose file descriptor number is
|
|
.I fildes\^
|
|
(1 by default)
|
|
is associated with a terminal device.
|
|
.TP
|
|
.BI \-z " s1\^"
|
|
true if the length of string
|
|
.I s1\^
|
|
is zero.
|
|
.TP
|
|
.BI \-n " s1\^"
|
|
true if the length of the string
|
|
.I s1\^
|
|
is non-zero.
|
|
.TP
|
|
.IB s1 " = " s2\^
|
|
true
|
|
if strings
|
|
.I s1\^
|
|
and
|
|
.I s2\^
|
|
are identical.
|
|
.TP
|
|
.IB s1 " != " s2\^
|
|
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
|
|
.IB n1 " \-eq " n2\^
|
|
true if the integers
|
|
.I n1\^
|
|
and
|
|
.I n2\^
|
|
are algebraically equal.
|
|
Any of the comparisons
|
|
.BR \-ne ,
|
|
.BR \-gt ,
|
|
.BR \-ge ,
|
|
.BR \-lt ,
|
|
and
|
|
.BR \-le
|
|
may be used in place of
|
|
.BR \-eq .
|
|
.TP
|
|
.BI \-L " file\^"
|
|
true if \f2file\f1 exists and is a symbolic link.
|
|
.br
|
|
.ne 6
|
|
.PP
|
|
These primaries may be combined with the
|
|
following operators:
|
|
.TP 12
|
|
.B !
|
|
unary negation operator.
|
|
.TP
|
|
.B \-a
|
|
binary
|
|
.I and\^
|
|
operator.
|
|
.TP
|
|
.B \-o
|
|
binary
|
|
.I or\^
|
|
operator
|
|
.RB ( \-a
|
|
has higher precedence than
|
|
.BR \-o ).
|
|
.TP
|
|
.BR "(\| " "expr" " \|)"
|
|
parentheses for grouping.
|
|
Notice also that parentheses are meaningful
|
|
to the shell and, therefore, must be quoted.
|
|
.SH "SEE ALSO"
|
|
find(1), sh(1).
|
|
.br
|
|
.ne 4v
|
|
.SH WARNING
|
|
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
|
|
.I group\^
|
|
or
|
|
.I other\^
|
|
bit set for that permission.
|
|
The correct exit status will be set if you are super-user.
|
|
.PP
|
|
The
|
|
.B "="
|
|
and
|
|
.B !=
|
|
operators have a higher precedence than the
|
|
.B \-r
|
|
through
|
|
.B \-n
|
|
operators,
|
|
and
|
|
.B =
|
|
and
|
|
.B !=
|
|
always expect arguments;
|
|
therefore,
|
|
.B =
|
|
and
|
|
.B !=
|
|
cannot be used with the
|
|
.B \-r
|
|
through
|
|
.B \-n
|
|
operators.
|
|
.PP
|
|
If more than one argument follows the
|
|
.B \-r
|
|
through
|
|
.B \-n
|
|
operators,
|
|
only the first argument is examined;
|
|
the others are ignored,
|
|
unless a
|
|
.B \-a
|
|
or a
|
|
.B \-o
|
|
is the second argument.
|
|
.\" @(#)test.1 6.2 of 9/2/83
|
|
.Ee
|
|
'\".so /pubs/tools/origin.att
|