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