xref: /freebsd/bin/test/test.1 (revision afe61c15161c324a7af299a9b8457aba5afc92db)
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.\"
37.Dd May 31, 1993
38.Dt TEST 1
39.Os
40.Sh NAME
41.Nm test
42.Nd condition evaluation utility
43.Sh SYNOPSIS
44.Nm test
45.Ar expression
46.Sh DESCRIPTION
47The
48.Nm test
49utility evaluates the expression and, if it evaluates
50to true, returns a zero (true) exit status; otherwise
51it returns 1 (false).
52If there is no expression, test also
53returns 1 (false).
54.Pp
55All operators and flags are separate arguments to the
56.Nm test
57utility.
58.Pp
59The following primaries are used to construct expression:
60.Bl -tag -width Ar
61.It Fl b Ar file
62True if
63.Ar file
64exists and is a block special
65file.
66.It Fl c Ar file
67True if
68.Ar file
69exists and is a character
70special file.
71.It Fl d Ar file
72True if
73.Ar file
74exists and is a directory.
75.It Fl e Ar file
76True if
77.Ar file
78exists (regardless of type).
79.It Fl f Ar file
80True if
81.Ar file
82exists and is a regular file.
83.It Fl g Ar file
84True if
85.Ar file
86exists and its set group ID flag
87is set.
88.It Fl h Ar file
89True if
90.Ar file
91exists and is a symbolic link.
92.It Fl n Ar string
93True if the length of
94.Ar string
95is nonzero.
96.It Fl p Ar file
97True if
98.Ar file
99is a named pipe
100.Po Tn FIFO Pc .
101.It Fl r Ar file
102True if
103.Ar file exists and is readable.
104.It Fl s Ar file
105True if
106.Ar file
107exists and has a size greater
108than zero.
109.It Fl t Ar [file_descriptor]
110True if the file whose file descriptor number
111is
112.Ar file_descriptor
113(default 1) is open and is
114associated with a terminal.
115.It Fl u Ar file
116True if
117.Ar file
118exists and its set user ID flag
119is set.
120.It Fl w Ar file
121True if
122.Ar file
123exists and is writable.
124True
125indicates only that the write flag is on.
126The file is not writable on a read-only file
127system even if this test indicates true.
128.It Fl x Ar file
129True if
130.Ar file
131exists and is executable.
132True
133indicates only that the execute flag is on.
134If
135.Ar file
136is a directory, true indicates that
137.Ar file
138can be searched.
139.It Fl z Ar string
140True if the length of
141.Ar string
142is zero.
143.It Ar string
144True if
145.Ar string
146is not the null
147string.
148.It Ar \&s\&1 Cm \&= Ar \&s\&2
149True if the strings
150.Ar \&s\&1
151and
152.Ar \&s\&2
153are identical.
154.It Ar \&s\&1 Cm \&!= Ar \&s\&2
155True if the strings
156.Ar \&s\&1
157and
158.Ar \&s\&2
159are not identical.
160.It Ar \&n\&1 Fl \&eq Ar \&n\&2
161True if the integers
162.Ar \&n\&1
163and
164.Ar \&n\&2
165are algebraically
166equal.
167.It Ar \&n\&1 Fl \&ne Ar \&n\&2
168True if the integers
169.Ar \&n\&1
170and
171.Ar \&n\&2
172are not
173algebraically equal.
174.It Ar \&n\&1 Fl \&gt Ar \&n\&2
175True if the integer
176.Ar \&n\&1
177is algebraically
178greater than the integer
179.Ar \&n\&2 .
180.It Ar \&n\&1 Fl \&ge Ar \&n\&2
181True if the integer
182.Ar \&n\&1
183is algebraically
184greater than or equal to the integer
185.Ar \&n\&2 .
186.It Ar \&n\&1 Fl \&lt Ar \&n\&2
187True if the integer
188.Ar \&n\&1
189is algebraically less
190than the integer
191.Ar \&n\&2 .
192.It Ar \&n\&1 Fl \&le Ar \&n\&2
193True if the integer
194.Ar \&n\&1
195is algebraically less
196than or equal to the integer
197.Ar \&n\&2 .
198.El
199.Pp
200These primaries can be combined with the following operators:
201.Bl -tag -width Ar
202.It Cm \&! Ar expression
203True if
204.Ar expression
205is false.
206.It Ar expression1 Fl a Ar expression2
207True if both
208.Ar expression1
209and
210.Ar expression2
211are true.
212.It Ar expression1 Fl o Ar expression2
213True if either
214.Ar expression1
215or
216.Ar expression2
217are true.
218.It Cm \&( Ns Ar expression Ns Cm \&)
219True if expression is true.
220.El
221.Pp
222The
223.Fl a
224operator has higher precedence than the
225.Fl o
226operator.
227.Sh GRAMMAR AMBIGUITY
228The
229.Nm test
230grammar is inherently ambiguous.  In order to assure a degree of consistency,
231the cases described in the
232.St -p1003.2 ,
233section D11.2/4.62.4, standard
234are evaluated consistently according to the rules specified in the
235standards document.  All other cases are subject to the ambiguity in the
236command semantics.
237.Sh RETURN VALUES
238The
239.Nm test
240utility exits with one of the following values:
241.Bl -tag -width Ds
242.It 0
243expression evaluated to true.
244.It 1
245expression evaluated to false or expression was
246missing.
247.It >1
248An error occurred.
249.El
250.Sh STANDARDS
251The
252.Nm test
253function is expected to be
254.St -p1003.2
255compatible.
256