xref: /freebsd/bin/test/test.1 (revision ce834215a70ff69e7e222827437116eee2f9ac6f)
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.4 1997/02/22 14:06:23 peter 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 test
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 test
58utility.
59.Pp
60The following primaries are used to construct expression:
61.Bl -tag -width Ar
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 r Ar file
103True if
104.Ar file
105exists and is readable.
106.It Fl s Ar file
107True if
108.Ar file
109exists and has a size greater
110than zero.
111.It Fl t Ar [file_descriptor]
112True if the file whose file descriptor number
113is
114.Ar file_descriptor
115(default 1) is open and is
116associated with a terminal.
117.It Fl u Ar file
118True if
119.Ar file
120exists and its set user ID flag
121is set.
122.It Fl w Ar file
123True if
124.Ar file
125exists and is writable.
126True
127indicates only that the write flag is on.
128The file is not writable on a read-only file
129system even if this test indicates true.
130.It Fl x Ar file
131True if
132.Ar file
133exists and is executable.
134True
135indicates only that the execute flag is on.
136If
137.Ar file
138is a directory, true indicates that
139.Ar file
140can be searched.
141.It Fl z Ar string
142True if the length of
143.Ar string
144is zero.
145.It Ar string
146True if
147.Ar string
148is not the null
149string.
150.It Ar \&s\&1 Cm \&= Ar \&s\&2
151True if the strings
152.Ar \&s\&1
153and
154.Ar \&s\&2
155are identical.
156.It Ar \&s\&1 Cm \&!= Ar \&s\&2
157True if the strings
158.Ar \&s\&1
159and
160.Ar \&s\&2
161are not identical.
162.It Ar \&n\&1 Fl \&eq Ar \&n\&2
163True if the integers
164.Ar \&n\&1
165and
166.Ar \&n\&2
167are algebraically
168equal.
169.It Ar \&n\&1 Fl \&ne Ar \&n\&2
170True if the integers
171.Ar \&n\&1
172and
173.Ar \&n\&2
174are not
175algebraically equal.
176.It Ar \&n\&1 Fl \&gt Ar \&n\&2
177True if the integer
178.Ar \&n\&1
179is algebraically
180greater than the integer
181.Ar \&n\&2 .
182.It Ar \&n\&1 Fl \&ge Ar \&n\&2
183True if the integer
184.Ar \&n\&1
185is algebraically
186greater than or equal to the integer
187.Ar \&n\&2 .
188.It Ar \&n\&1 Fl \&lt Ar \&n\&2
189True if the integer
190.Ar \&n\&1
191is algebraically less
192than the integer
193.Ar \&n\&2 .
194.It Ar \&n\&1 Fl \&le Ar \&n\&2
195True if the integer
196.Ar \&n\&1
197is algebraically less
198than or equal to the integer
199.Ar \&n\&2 .
200.El
201.Pp
202These primaries can be combined with the following operators:
203.Bl -tag -width Ar
204.It Cm \&! Ar expression
205True if
206.Ar expression
207is false.
208.It Ar expression1 Fl a Ar expression2
209True if both
210.Ar expression1
211and
212.Ar expression2
213are true.
214.It Ar expression1 Fl o Ar expression2
215True if either
216.Ar expression1
217or
218.Ar expression2
219are true.
220.It Cm \&( Ns Ar expression Ns Cm \&)
221True if expression is true.
222.El
223.Pp
224The
225.Fl a
226operator has higher precedence than the
227.Fl o
228operator.
229.Sh GRAMMAR AMBIGUITY
230The
231.Nm test
232grammar is inherently ambiguous.  In order to assure a degree of consistency,
233the cases described in the
234.St -p1003.2 ,
235section D11.2/4.62.4, standard
236are evaluated consistently according to the rules specified in the
237standards document.  All other cases are subject to the ambiguity in the
238command semantics.
239.Sh RETURN VALUES
240The
241.Nm test
242utility exits with one of the following values:
243.Bl -tag -width Ds
244.It 0
245expression evaluated to true.
246.It 1
247expression evaluated to false or expression was
248missing.
249.It >1
250An error occurred.
251.El
252.Sh STANDARDS
253The
254.Nm test
255function is expected to be
256.St -p1003.2
257compatible.
258