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
174 exists and is newer than
176 .It Ar file1 Fl ot Ar file2
179 exists and is older than
181 .It Ar file1 Fl ef Ar file2
186 exist and refer to the same file.
198 .It Ar s1 Cm != Ar s2
209 based on the binary value of their characters.
215 based on the binary value of their characters.
216 .It Ar n1 Fl eq Ar n2
223 .It Ar n1 Fl ne Ar n2
230 .It Ar n1 Fl gt Ar n2
234 greater than the integer
236 .It Ar n1 Fl ge Ar n2
240 greater than or equal to the integer
242 .It Ar n1 Fl lt Ar n2
245 is algebraically less
248 .It Ar n1 Fl le Ar n2
251 is algebraically less
252 than or equal to the integer
260 will fully dereference it and then evaluate the expression
261 against the file referenced, except for the
267 These primaries can be combined with the following operators:
269 .It Cm \&! Ar expression
273 .It Ar expression1 Fl a Ar expression2
279 .It Ar expression1 Fl o Ar expression2
285 .It Cm \&( Ar expression Cm \&)
286 True if expression is true.
291 operator has higher precedence than the
295 Some shells may provide a builtin
297 command which is similar or identical to this utility.
301 .Sh GRAMMAR AMBIGUITY
304 grammar is inherently ambiguous.
305 In order to assure a degree of consistency,
306 the cases described in the
308 section D11.2/4.62.4, standard
309 are evaluated consistently according to the rules specified in the
311 All other cases are subject to the ambiguity in the
314 In particular, only expressions containing
324 utility exits with one of the following values:
325 .Bl -tag -width indent
327 expression evaluated to true.
329 expression evaluated to false or expression was
336 .Li test FILE1 -nt FILE2
341 .Dl test -n \&"$(find -L -- FILE1 -prune -newer FILE2 2>/dev/null)\&"
343 This can be modified using non-standard
347 to compare other timestamps.
349 For compatibility with some other implementations,
352 primary can be substituted with
354 with the same meaning.
365 utility implements a superset of the
380 Both sides are always evaluated in
384 For instance, the writable status of
386 will be tested by the following command even though the former expression
387 indicated false, which results in a gratuitous access to the file system:
388 .Dl "[ -z abc -a -w file ]"
390 .Dl "[ -z abc ] && [ -w file ]"