2 .\" Copyright (c) 1991, 1993
3 .\" The Regents of the University of California. All rights reserved.
5 .\" This code is derived from software contributed to Berkeley by
6 .\" the Institute of Electrical and Electronics Engineers, Inc.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)test.1 8.1 (Berkeley) 5/31/93
41 .Nd condition evaluation utility
50 utility evaluates the expression and, if it evaluates
51 to true, returns a zero (true) exit status; otherwise
53 If there is no expression,
58 All operators and flags are separate arguments to the
62 The following primaries are used to construct expression:
67 exists and is a block special
72 exists and is a character
77 exists and is a directory.
81 exists (regardless of type).
85 exists and is a regular file.
89 exists and its set group ID flag
94 exists and is a symbolic link.
95 This operator is retained for compatibility with previous versions of
97 Do not rely on its existence; use
103 exists and its sticky bit is set.
105 True if the length of
116 exists and is readable.
120 exists and has a size greater
122 .It Fl t Ar file_descriptor
123 True if the file whose file descriptor number
126 is open and is associated with a terminal.
130 exists and its set user ID flag
135 exists and is writable.
137 indicates only that the write flag is on.
138 The file is not writable on a read-only file
139 system even if this test indicates true.
143 exists and is executable.
145 indicates only that the execute flag is on.
148 is a directory, true indicates that
152 True if the length of
158 exists and is a symbolic link.
162 exists and its owner matches the effective user id of this process.
166 exists and its group matches the effective group id of this process.
170 exists and is a socket.
171 .It Ar file1 Fl nt Ar file2
180 .It Ar file1 Fl nt Ns Ar X Ns Ar Y Ar file2
187 has a more recent last access time
188 .Pq Ar X Ns = Ns Cm a ,
190 .Pq Ar X Ns = Ns Cm b ,
192 .Pq Ar X Ns = Ns Cm c ,
194 .Pq Ar X Ns = Ns Cm m
195 than the last access time
196 .Pq Ar Y Ns = Ns Cm a ,
198 .Pq Ar Y Ns = Ns Cm b ,
200 .Pq Ar Y Ns = Ns Cm c ,
202 .Pq Ar Y Ns = Ns Cm m
209 .It Ar file1 Fl ot Ar file2
226 .It Ar file1 Fl ot Ns Ar X Ns Ar Y Ar file2
229 .Ic -nt Ns Ar Y Ns Ar X
231 .It Ar file1 Fl ef Ar file2
236 exist and refer to the same file.
248 .It Ar s1 Cm != Ar s2
259 based on the binary value of their characters.
265 based on the binary value of their characters.
266 .It Ar n1 Fl eq Ar n2
273 .It Ar n1 Fl ne Ar n2
280 .It Ar n1 Fl gt Ar n2
284 greater than the integer
286 .It Ar n1 Fl ge Ar n2
290 greater than or equal to the integer
292 .It Ar n1 Fl lt Ar n2
295 is algebraically less
298 .It Ar n1 Fl le Ar n2
301 is algebraically less
302 than or equal to the integer
310 will fully dereference it and then evaluate the expression
311 against the file referenced, except for the
317 These primaries can be combined with the following operators:
319 .It Cm \&! Ar expression
323 .It Ar expression1 Fl a Ar expression2
329 .It Ar expression1 Fl o Ar expression2
335 .It Cm \&( Ar expression Cm \&)
336 True if expression is true.
341 operator has higher precedence than the
345 Some shells may provide a builtin
347 command which is similar or identical to this utility.
351 .Sh GRAMMAR AMBIGUITY
354 grammar is inherently ambiguous.
355 In order to assure a degree of consistency,
356 the cases described in the
358 section D11.2/4.62.4, standard
359 are evaluated consistently according to the rules specified in the
361 All other cases are subject to the ambiguity in the
364 In particular, only expressions containing
374 utility exits with one of the following values:
375 .Bl -tag -width indent
377 expression evaluated to true.
379 expression evaluated to false or expression was
385 For compatibility with some other implementations,
388 primary can be substituted with
390 with the same meaning.
399 utility implements a superset of the
403 Both sides are always evaluated in
407 For instance, the writable status of
409 will be tested by the following command even though the former expression
410 indicated false, which results in a gratuitous access to the file system:
411 .Dl "[ -z abc -a -w file ]"
413 .Dl "[ -z abc ] && [ -w file ]"