xref: /freebsd/bin/test/test.1 (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
1.\" Copyright (c) 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)test.1	8.1 (Berkeley) 5/31/93
36.\"	$Id: test.1,v 1.7 1998/09/07 16:59:05 cracauer Exp $
37.\"
38.Dd May 31, 1993
39.Dt TEST 1
40.Os
41.Sh NAME
42.Nm test
43.Nd condition evaluation utility
44.Sh SYNOPSIS
45.Nm test
46.Ar expression
47.Sh DESCRIPTION
48The
49.Nm
50utility evaluates the expression and, if it evaluates
51to true, returns a zero (true) exit status; otherwise
52it returns 1 (false).
53If there is no expression, test also
54returns 1 (false).
55.Pp
56All operators and flags are separate arguments to the
57.Nm
58utility.
59.Pp
60The following primaries are used to construct expression:
61.Bl -tag -width indent
62.It Fl b Ar file
63True if
64.Ar file
65exists and is a block special
66file.
67.It Fl c Ar file
68True if
69.Ar file
70exists and is a character
71special file.
72.It Fl d Ar file
73True if
74.Ar file
75exists and is a directory.
76.It Fl e Ar file
77True if
78.Ar file
79exists (regardless of type).
80.It Fl f Ar file
81True if
82.Ar file
83exists and is a regular file.
84.It Fl g Ar file
85True if
86.Ar file
87exists and its set group ID flag
88is set.
89.It Fl h Ar file
90True if
91.Ar file
92exists and is a symbolic link.
93.It Fl n Ar string
94True if the length of
95.Ar string
96is nonzero.
97.It Fl p Ar file
98True if
99.Ar file
100is a named pipe
101.Po Tn FIFO Pc .
102.It Fl S Ar file
103True if
104.Ar file
105is a socket.
106.It Fl r Ar file
107True if
108.Ar file
109exists and is readable.
110.It Fl s Ar file
111True if
112.Ar file
113exists and has a size greater
114than zero.
115.It Fl t Ar [file_descriptor]
116True if the file whose file descriptor number
117is
118.Ar file_descriptor
119(default 1) is open and is
120associated with a terminal.
121.It Fl u Ar file
122True if
123.Ar file
124exists and its set user ID flag
125is set.
126.It Fl w Ar file
127True if
128.Ar file
129exists and is writable.
130True
131indicates only that the write flag is on.
132The file is not writable on a read-only file
133system even if this test indicates true.
134.It Fl x Ar file
135True if
136.Ar file
137exists and is executable.
138True
139indicates only that the execute flag is on.
140If
141.Ar file
142is a directory, true indicates that
143.Ar file
144can be searched.
145.It Fl z Ar string
146True if the length of
147.Ar string
148is zero.
149.It Ar string
150True if
151.Ar string
152is not the null
153string.
154.It Ar \&s\&1 Cm \&= Ar \&s\&2
155True if the strings
156.Ar \&s\&1
157and
158.Ar \&s\&2
159are identical.
160.It Ar \&s\&1 Cm \&!= Ar \&s\&2
161True if the strings
162.Ar \&s\&1
163and
164.Ar \&s\&2
165are not identical.
166.It Ar \&n\&1 Fl \&eq Ar \&n\&2
167True if the integers
168.Ar \&n\&1
169and
170.Ar \&n\&2
171are algebraically
172equal.
173.It Ar \&n\&1 Fl \&ne Ar \&n\&2
174True if the integers
175.Ar \&n\&1
176and
177.Ar \&n\&2
178are not
179algebraically equal.
180.It Ar \&n\&1 Fl \&gt Ar \&n\&2
181True if the integer
182.Ar \&n\&1
183is algebraically
184greater than the integer
185.Ar \&n\&2 .
186.It Ar \&n\&1 Fl \&ge Ar \&n\&2
187True if the integer
188.Ar \&n\&1
189is algebraically
190greater than or equal to the integer
191.Ar \&n\&2 .
192.It Ar \&n\&1 Fl \&lt Ar \&n\&2
193True if the integer
194.Ar \&n\&1
195is algebraically less
196than the integer
197.Ar \&n\&2 .
198.It Ar \&n\&1 Fl \&le Ar \&n\&2
199True if the integer
200.Ar \&n\&1
201is algebraically less
202than or equal to the integer
203.Ar \&n\&2 .
204.El
205.Pp
206These primaries can be combined with the following operators:
207.Bl -tag -width Ar
208.It Cm \&! Ar expression
209True if
210.Ar expression
211is false.
212.It Ar expression1 Fl a Ar expression2
213True if both
214.Ar expression1
215and
216.Ar expression2
217are true.
218.It Ar expression1 Fl o Ar expression2
219True if either
220.Ar expression1
221or
222.Ar expression2
223are true.
224.It Cm \&( Ns Ar expression Ns Cm \&)
225True if expression is true.
226.El
227.Pp
228The
229.Fl a
230operator has higher precedence than the
231.Fl o
232operator.
233.Sh GRAMMAR AMBIGUITY
234The
235.Nm
236grammar is inherently ambiguous.  In order to assure a degree of consistency,
237the cases described in the
238.St -p1003.2 ,
239section D11.2/4.62.4, standard
240are evaluated consistently according to the rules specified in the
241standards document.  All other cases are subject to the ambiguity in the
242command semantics.
243.Sh RETURN VALUES
244The
245.Nm
246utility exits with one of the following values:
247.Bl -tag -width Ds
248.It 0
249expression evaluated to true.
250.It 1
251expression evaluated to false or expression was
252missing.
253.It >1
254An error occurred.
255.El
256.Sh SEE ALSO
257.Xr expr 1 ,
258.Xr sh 1
259.Sh STANDARDS
260The
261.Nm
262function is expected to be
263.St -p1003.2
264compatible.
265