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
33 .\" $FreeBSD: src/bin/test/test.1,v 1.31 2010/09/11 10:49:56 brucec Exp $
35 .Dd September 10, 2010
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,
55 also returns 1 (false).
57 All operators and flags are separate arguments to the
61 The following primaries are used to construct expression:
66 exists and is a block special
71 exists and is a character
76 exists and is a directory.
80 exists (regardless of type).
84 exists and is a regular file.
88 exists and its set group ID flag
93 exists and is a symbolic link.
94 This operator is retained for compatibility with previous versions of
96 Do not rely on its existence; use
102 exists and its sticky bit is set.
104 True if the length of
115 exists and is readable.
119 exists and has a size greater
121 .It Fl t Ar file_descriptor
122 True if the file whose file descriptor number
125 is open and is associated with a terminal.
129 exists and its set user ID flag
134 exists and is writable.
136 indicates both that the write flag is on and that
138 resides on a read-write file system.
140 Note that this behaviour is specific to
142 When writing portable scripts, keep in mind that
143 on some systems, this test may
144 indicate only that the write flag is on.
148 exists and is executable.
150 indicates only that the execute flag is on.
153 is a directory, true indicates that
157 True if the length of
163 exists and is a symbolic link.
167 exists and its owner matches the effective user id of this process.
171 exists and its group matches the effective group id of this process.
175 exists and is a socket.
176 .It Ar file1 Fl nt Ar file2
179 exists and is newer than
181 .It Ar file1 Fl ot Ar file2
184 exists and is older than
186 .It Ar file1 Fl ef Ar file2
191 exist and refer to the same file.
203 .It Ar s1 Cm != Ar s2
214 based on the binary value of their characters.
220 based on the binary value of their characters.
221 .It Ar n1 Fl eq Ar n2
228 .It Ar n1 Fl ne Ar n2
235 .It Ar n1 Fl gt Ar n2
239 greater than the integer
241 .It Ar n1 Fl ge Ar n2
245 greater than or equal to the integer
247 .It Ar n1 Fl lt Ar n2
250 is algebraically less
253 .It Ar n1 Fl le Ar n2
256 is algebraically less
257 than or equal to the integer
265 will fully dereference it and then evaluate the expression
266 against the file referenced, except for the
272 These primaries can be combined with the following operators:
274 .It Cm \&! Ar expression
278 .It Ar expression1 Fl a Ar expression2
284 .It Ar expression1 Fl o Ar expression2
290 .It Cm \&( Ar expression Cm \&)
291 True if expression is true.
296 operator has higher precedence than the
300 Some shells may provide a builtin
302 command which is similar or identical to this utility.
306 .Sh GRAMMAR AMBIGUITY
309 grammar is inherently ambiguous.
310 In order to assure a degree of consistency,
311 the cases described in the
313 section D11.2/4.62.4, standard
314 are evaluated consistently according to the rules specified in the
316 All other cases are subject to the ambiguity in the
319 In particular, only expressions containing
329 utility exits with one of the following values:
330 .Bl -tag -width indent
332 expression evaluated to true.
334 expression evaluated to false or expression was
347 utility implements a superset of the
351 Both sides are always evaluated in
355 For instance, the writable status of
357 will be tested by the following command even though the former expression
358 indicated false, which results in a gratuitous access to the file system:
359 .Dl "[ -z abc -a -w file ]"
361 .Dl "[ -z abc ] && [ -w file ]"