xref: /csrg-svn/old/test/test.1 (revision 50790)
148537Scael.\" Copyright (c) 1991 Regents of the University of California.
248537Scael.\" All rights reserved.
319509Smckusick.\"
450211Sbostic.\" This code is derived from software contributed to Berkeley by
550211Sbostic.\" the Institute of Electrical and Electronics Engineers, Inc.
650211Sbostic.\"
748537Scael.\" %sccs.include.redist.roff%
848537Scael.\"
9*50790Scael.\"     @(#)test.1	6.5 (Berkeley) 08/06/91
1048537Scael.\"
1148537Scael.Dd
1248537Scael.Dt TEST 1
13*50790Scael.Os
1448537Scael.Sh NAME
1548537Scael.Nm test
1648537Scael.Nd Condition evaluation utility.
1748537Scael.Sh SYNOPSIS
1848537Scael.Nm test
1948537Scael.Ar expression
2048537Scael.Sh DESCRIPTION
2148537ScaelThe
2248537Scael.Nm test
2348537Scaelutility evaluates the expression and, if it evaluates
2448537Scaelto true, returns a zero (true) exit status; otherwise
2548537Scaelit returns 1 (false).
2648537ScaelIf there is no expression, test also
2748537Scaelreturns 1 (false).
2848537Scael.Pp
2948537ScaelAll operators and flags are separate arguments to the
3048537Scael.Nm test
3148537Scaelutility.
3248537Scael.Pp
3348537ScaelThe following primaries are used to construct expression:
3448537Scael.Bl -tag -width Ar
3548537Scael.It Fl b Ar file
3648537ScaelTrue if
3748537Scael.Ar file
3848537Scaelexists and is a block special
3948537Scaelfile.
4048537Scael.It Fl c Ar file
4148537ScaelTrue if
4248537Scael.Ar file
4348537Scaelexists and is a character
4448537Scaelspecial file.
4548537Scael.It Fl d Ar file
4648537ScaelTrue if
4748537Scael.Ar file
4848537Scaelexists and is a directory.
4948537Scael.It Fl f Ar file
5048537ScaelTrue if
5148537Scael.Ar file
5248537Scaelexists and is a regular file.
5348537Scael.It Fl g Ar file
5448537ScaelTrue if
5548537Scael.Ar file
5648537Scaelexists and its set group ID flag
5748537Scaelis set.
5848537Scael.It Fl n Ar string
5948537ScaelTrue if the length of
6048537Scael.Ar string
6148537Scaelis nonzero.
6248537Scael.It Fl p Ar file
6348537ScaelTrue if
6448537Scael.Ar file
6548537Scaelis a named pipe
6648537Scael.Po Tn FIFO Pc .
6748537Scael.It Fl r Ar file
6848537ScaelTrue if
6948537Scael.Ar file exists and is readable.
7048537Scael.It Fl s Ar file
7148537ScaelTrue if
7248537Scael.Ar file
7348537Scaelexists and has a size greater
7448537Scaelthan zero.
7548537Scael.It Fl t Ar [file_descriptor]
7648537ScaelTrue if the file whose file descriptor number
7748537Scaelis
7848537Scael.Ar file_descriptor
7948537Scael(default 1) is open and is
8048537Scaelassociated with a terminal.
8148537Scael.It Fl u Ar file
8248537ScaelTrue if
8348537Scael.Ar file
8448537Scaelexists and its set user ID flag
8548537Scaelis set.
8648537Scael.It Fl w Ar file
8748537ScaelTrue if
8848537Scael.Ar file
8948537Scaelexists and is writable.
9048537ScaelTrue
9148537Scaelindicates only that the write flag is on.
9248537ScaelThe file is not writable on a read-only file
9348537Scaelsystem even if this test indicates true.
9448537Scael.It Fl x Ar file
9548537ScaelTrue if
9648537Scael.Ar file
9748537Scaelexists and is executable.
9848537ScaelTrue
9948537Scaelindicates only that the execute flag is on.
10048537ScaelIf
10148537Scael.Ar file
10248537Scaelis a directory, true indicates that
10348537Scael.Ar file
10448537Scaelcan be searched.
10548537Scael.It Fl z Ar string
10648537ScaelTrue if the length of
10748537Scael.Ar string
10819509Smckusickis zero.
10948537Scael.It Ar string
11048537ScaelTrue if
11148537Scael.Ar string
11248537Scaelis not the null
11348537Scaelstring.
11448537Scael.It Ar \&s\&1 Cm \&= Ar \&s\&2
11548537ScaelTrue if the strings
11648537Scael.Ar \&s\&1
11719509Smckusickand
11848537Scael.Ar \&s\&2
11948537Scaelare identical.
12048537Scael.It Ar \&s\&1 Cm \&!= Ar \&s\&2
12148537ScaelTrue if the strings
12248537Scael.Ar \&s\&1
12319509Smckusickand
12448537Scael.Ar \&s\&2
12548537Scaelare not identical.
12648537Scael.It Ar \&n\&1 Fl \&eq Ar \&n\&2
12748537ScaelTrue if the integers
12848537Scael.Ar \&n\&1
12919509Smckusickand
13048537Scael.Ar \&n\&2
13148537Scaelare algebraically
13248537Scaelequal.
13348537Scael.It Ar \&n\&1 Fl \&ne Ar \&n\&2
13448537ScaelTrue if the integers
13548537Scael.Ar \&n\&1
13648537Scaeland
13748537Scael.Ar \&n\&2
13848537Scaelare not
13948537Scaelalgebraically equal.
14048537Scael.It Ar \&n\&1 Fl \&gt Ar \&n\&2
14148537ScaelTrue if the integer
14248537Scael.Ar \&n\&1
14348537Scaelis algebraically
14448537Scaelgreater than the integer
14548537Scael.Ar \&n\&2 .
14648537Scael.It Ar \&n\&1 Fl \&ge Ar \&n\&2
14748537ScaelTrue if the integer
14848537Scael.Ar \&n\&1
14948537Scaelis algebraically
15048537Scaelgreater than or equal to the integer
15148537Scael.Ar \&n\&2 .
15248537Scael.It Ar \&n\&1 Fl \&lt Ar \&n\&2
15348537ScaelTrue if the integer
15448537Scael.Ar \&n\&1
15548537Scaelis algebraically less
15648537Scaelthan the integer
15748537Scael.Ar \&n\&2 .
15848537Scael.It Ar \&n\&1 Fl \&le Ar \&n\&2
15948537ScaelTrue if the integer
16048537Scael.Ar \&n\&1
16148537Scaelis algebraically less
16248537Scaelthan or equal to the integer
16348537Scael.Ar \&n\&2 .
16448537Scael.El
16548537Scael.Pp
16648537ScaelThese primaries can be combined with the following operators:
16748537Scael.Bl -tag -width Ar
16848537Scael.It Cm \&! Ar expression
16948537ScaelTrue if
17048537Scael.Ar expression
17148537Scaelis false.
17248537Scael.It Ar expression1 Fl a Ar expression2
17348537ScaelTrue if both
17448537Scael.Ar expression1
17548537Scaeland
17648537Scael.Ar expression2
17748537Scaelare true.
17848537Scael.It Ar expression1 Fl o Ar expression2
17948537ScaelTrue if either
18048537Scael.Ar expression1
18119509Smckusickor
18248537Scael.Ar expression2
18348537Scaelare true.
18448537Scael.It Cm \&( Ns Ar expression Ns Cm \&)
18548537ScaelTrue if expression is true.
18648537Scael.El
18748537Scael.Pp
18848537ScaelThe
18948537Scael.Fl a
19048537Scaeloperator has higher precedence than the
19148537Scael.Fl o
19248537Scaeloperator.
19348537Scael.Pp
19448537ScaelThe
19548537Scael.Nm test
19648537Scaelutility exits with one of the following values:
19748537Scael.Bl -tag -width Ds
19848537Scael.It 0
19948537Scaelexpression evaluated to true.
20048537Scael.It 1
20148537Scaelexpression evaluated to false or expression was
20248537Scaelmissing.
20348537Scael.It >1
20448537ScaelAn error occurred.
20548537Scael.El
20648537Scael.Sh STANDARDS
20748537ScaelThe
20848537Scael.Nm test
20948537Scaelfunction is expected to be
210*50790Scael.St -p1003.2
211*50790Scaelcompatible.
212