xref: /dragonfly/bin/test/test.1 (revision 49781055)
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.\" $FreeBSD: src/bin/test/test.1,v 1.11.2.5 2001/12/14 14:22:09 ru Exp $
37.\" $DragonFly: src/bin/test/test.1,v 1.5 2005/08/01 01:49:16 swildner Exp $
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
48.Ar expression
49.Nm \&[
50.Ar expression Cm ]
51.Sh DESCRIPTION
52The
53.Nm
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
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.
97This operator is retained for compatibility with previous versions of
98this program.
99Do not rely on its existence; use
100.Fl L
101instead.
102.It Fl k Ar file
103True if
104.Ar file
105exists and its sticky bit is set.
106.It Fl n Ar string
107True if the length of
108.Ar string
109is nonzero.
110.It Fl p Ar file
111True if
112.Ar file
113is a named pipe
114.Pq Tn FIFO .
115.It Fl r Ar file
116True if
117.Ar file
118exists and is readable.
119.It Fl s Ar file
120True if
121.Ar file
122exists and has a size greater
123than zero.
124.It Fl t Ar file_descriptor
125True if the file whose file descriptor number
126is
127.Ar file_descriptor
128is open and is associated with a terminal.
129.It Fl u Ar file
130True if
131.Ar file
132exists and its set user ID flag
133is set.
134.It Fl w Ar file
135True if
136.Ar file
137exists and is writable.
138True
139indicates both that the write flag is on and that
140.Ar file
141resides on a read-write file system.
142.Pp
143Note that this behaviour is specific to
144.Dx .
145When writing portable scripts, keep in mind that
146on some systems, this test may
147indicate only that the write flag is on.
148.It Fl x Ar file
149True if
150.Ar file
151exists and is executable.
152True
153indicates only that the execute flag is on.
154If
155.Ar file
156is a directory, true indicates that
157.Ar file
158can be searched.
159.It Fl z Ar string
160True if the length of
161.Ar string
162is zero.
163.It Fl L Ar file
164True if
165.Ar file
166exists and is a symbolic link.
167.It Fl O Ar file
168True if
169.Ar file
170exists and its owner matches the effective user id of this process.
171.It Fl G Ar file
172True if
173.Ar file
174exists and its group matches the effective group id of this process.
175.It Fl S Ar file
176True if
177.Ar file
178exists and is a socket.
179.It Ar file1 Fl nt Ar file2
180True if
181.Ar file1
182exists and is newer than
183.Ar file2 .
184.It Ar file1 Fl ot Ar file2
185True if
186.Ar file1
187exists and is older than
188.Ar file2 .
189.It Ar file1 Fl ef Ar file2
190True if
191.Ar file1
192and
193.Ar file2
194exist and refer to the same file.
195.It Ar string
196True if
197.Ar string
198is not the null
199string.
200.It Ar \&s\&1 Cm \&= Ar \&s\&2
201True if the strings
202.Ar \&s\&1
203and
204.Ar \&s\&2
205are identical.
206.It Ar \&s\&1 Cm \&!= Ar \&s\&2
207True if the strings
208.Ar \&s\&1
209and
210.Ar \&s\&2
211are not identical.
212.It Ar \&s\&1 Cm \&< Ar \&s\&2
213True if string
214.Ar \&s\&1
215comes before
216.Ar \&s\&2
217based on the ASCII value of their characters.
218.It Ar \&s\&1 Cm \&> Ar \&s\&2
219True if string
220.Ar \&s\&1
221comes after
222.Ar \&s\&2
223based on the ASCII value of their characters.
224.It Ar \&s\&1
225True if
226.Ar \&s\&1
227is not the null
228string.
229.It Ar \&n\&1 Fl \&eq Ar \&n\&2
230True if the integers
231.Ar \&n\&1
232and
233.Ar \&n\&2
234are algebraically
235equal.
236.It Ar \&n\&1 Fl \&ne Ar \&n\&2
237True if the integers
238.Ar \&n\&1
239and
240.Ar \&n\&2
241are not
242algebraically equal.
243.It Ar \&n\&1 Fl \&gt Ar \&n\&2
244True if the integer
245.Ar \&n\&1
246is algebraically
247greater than the integer
248.Ar \&n\&2 .
249.It Ar \&n\&1 Fl \&ge Ar \&n\&2
250True if the integer
251.Ar \&n\&1
252is algebraically
253greater than or equal to the integer
254.Ar \&n\&2 .
255.It Ar \&n\&1 Fl \&lt Ar \&n\&2
256True if the integer
257.Ar \&n\&1
258is algebraically less
259than the integer
260.Ar \&n\&2 .
261.It Ar \&n\&1 Fl \&le Ar \&n\&2
262True if the integer
263.Ar \&n\&1
264is algebraically less
265than or equal to the integer
266.Ar \&n\&2 .
267.El
268.Pp
269These primaries can be combined with the following operators:
270.Bl -tag -width Ar
271.It Cm \&! Ar expression
272True if
273.Ar expression
274is false.
275.It Ar expression1 Fl a Ar expression2
276True if both
277.Ar expression1
278and
279.Ar expression2
280are true.
281.It Ar expression1 Fl o Ar expression2
282True if either
283.Ar expression1
284or
285.Ar expression2
286are true.
287.It Cm \&( Ns Ar expression Ns Cm \&)
288True if expression is true.
289.El
290.Pp
291The
292.Fl a
293operator has higher precedence than the
294.Fl o
295operator.
296.Pp
297Some shells may provide a builtin
298.Nm
299command which is similar or identical to this utility.
300Consult the
301.Xr builtin 1
302manual page.
303.Sh GRAMMAR AMBIGUITY
304The
305.Nm
306grammar is inherently ambiguous.  In order to assure a degree of consistency,
307the cases described in the
308.St -p1003.2 ,
309section D11.2/4.62.4, standard
310are evaluated consistently according to the rules specified in the
311standards document.  All other cases are subject to the ambiguity in the
312command semantics.
313.Sh RETURN VALUES
314The
315.Nm
316utility exits with one of the following values:
317.Bl -tag -width Ds
318.It 0
319expression evaluated to true.
320.It 1
321expression evaluated to false or expression was
322missing.
323.It >1
324An error occurred.
325.El
326.Sh SEE ALSO
327.Xr builtin 1 ,
328.Xr expr 1 ,
329.Xr sh 1
330.Sh STANDARDS
331The
332.Nm
333utility implements a superset of the
334.St -p1003.2
335specification.
336