mdoc conversion/bsd copyright
[unix-history] / usr / src / old / test / test.1
.\" Copyright (c) 1991 Regents of the University of California.
.\" All rights reserved.
.\"
.\" %sccs.include.redist.roff%
.\"
.\" @(#)test.1 6.3 (Berkeley) %G%
.\"
.Dd
.Dt TEST 1
.Os BSD 4.4
.Sh NAME
.Nm test
.Nd Condition evaluation utility.
.Sh SYNOPSIS
.Nm test
.Ar expression
.Sh DESCRIPTION
The
.Nm test
utility evaluates the expression and, if it evaluates
to true, returns a zero (true) exit status; otherwise
it returns 1 (false).
If there is no expression, test also
returns 1 (false).
.Pp
All operators and flags are separate arguments to the
.Nm test
utility.
.Pp
The following primaries are used to construct expression:
.Bl -tag -width Ar
.It Fl b Ar file
True if
.Ar file
exists and is a block special
file.
.It Fl c Ar file
True if
.Ar file
exists and is a character
special file.
.It Fl d Ar file
True if
.Ar file
exists and is a directory.
.It Fl f Ar file
True if
.Ar file
exists and is a regular file.
.It Fl g Ar file
True if
.Ar file
exists and its set group ID flag
is set.
.It Fl n Ar string
True if the length of
.Ar string
is nonzero.
.It Fl p Ar file
True if
.Ar file
is a named pipe
.Po Tn FIFO Pc .
.It Fl r Ar file
True if
.Ar file exists and is readable.
.It Fl s Ar file
True if
.Ar file
exists and has a size greater
than zero.
.It Fl t Ar [file_descriptor]
True if the file whose file descriptor number
is
.Ar file_descriptor
(default 1) is open and is
associated with a terminal.
.It Fl u Ar file
True if
.Ar file
exists and its set user ID flag
is set.
.It Fl w Ar file
True if
.Ar file
exists and is writable.
True
indicates only that the write flag is on.
The file is not writable on a read-only file
system even if this test indicates true.
.It Fl x Ar file
True if
.Ar file
exists and is executable.
True
indicates only that the execute flag is on.
If
.Ar file
is a directory, true indicates that
.Ar file
can be searched.
.It Fl z Ar string
True if the length of
.Ar string
is zero.
.It Ar string
True if
.Ar string
is not the null
string.
.It Ar \&s\&1 Cm \&= Ar \&s\&2
True if the strings
.Ar \&s\&1
and
.Ar \&s\&2
are identical.
.It Ar \&s\&1 Cm \&!= Ar \&s\&2
True if the strings
.Ar \&s\&1
and
.Ar \&s\&2
are not identical.
.It Ar \&n\&1 Fl \&eq Ar \&n\&2
True if the integers
.Ar \&n\&1
and
.Ar \&n\&2
are algebraically
equal.
.It Ar \&n\&1 Fl \&ne Ar \&n\&2
True if the integers
.Ar \&n\&1
and
.Ar \&n\&2
are not
algebraically equal.
.It Ar \&n\&1 Fl \&gt Ar \&n\&2
True if the integer
.Ar \&n\&1
is algebraically
greater than the integer
.Ar \&n\&2 .
.It Ar \&n\&1 Fl \&ge Ar \&n\&2
True if the integer
.Ar \&n\&1
is algebraically
greater than or equal to the integer
.Ar \&n\&2 .
.It Ar \&n\&1 Fl \&lt Ar \&n\&2
True if the integer
.Ar \&n\&1
is algebraically less
than the integer
.Ar \&n\&2 .
.It Ar \&n\&1 Fl \&le Ar \&n\&2
True if the integer
.Ar \&n\&1
is algebraically less
than or equal to the integer
.Ar \&n\&2 .
.El
.Pp
These primaries can be combined with the following operators:
.Bl -tag -width Ar
.It Cm \&! Ar expression
True if
.Ar expression
is false.
.It Ar expression1 Fl a Ar expression2
True if both
.Ar expression1
and
.Ar expression2
are true.
.It Ar expression1 Fl o Ar expression2
True if either
.Ar expression1
or
.Ar expression2
are true.
.It Cm \&( Ns Ar expression Ns Cm \&)
True if expression is true.
.El
.Pp
The
.Fl a
operator has higher precedence than the
.Fl o
operator.
.Pp
The
.Nm test
utility exits with one of the following values:
.Bl -tag -width Ds
.It 0
expression evaluated to true.
.It 1
expression evaluated to false or expression was
missing.
.It >1
An error occurred.
.El
.Sh STANDARDS
The
.Nm test
function is expected to be
.Tn POSIX
1003.2 compatible.