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