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 .\" 3. All advertising materials mentioning features or use of this software
17 .\" must display the following acknowledgement:
18 .\" This product includes software developed by the University of
19 .\" California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\" may be used to endorse or promote products derived from this software
22 .\" without specific prior written permission.
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .\" @(#)test.1 8.1 (Berkeley) 5/31/93
37 .\" $FreeBSD: src/bin/test/test.1,v 1.31 2010/09/11 10:49:56 brucec Exp $
39 .Dd September 10, 2010
45 .Nd condition evaluation utility
54 utility evaluates the expression and, if it evaluates
55 to true, returns a zero (true) exit status; otherwise
57 If there is no expression,
59 also returns 1 (false).
61 All operators and flags are separate arguments to the
65 The following primaries are used to construct expression:
70 exists and is a block special
75 exists and is a character
80 exists and is a directory.
84 exists (regardless of type).
88 exists and is a regular file.
92 exists and its set group ID flag
97 exists and is a symbolic link.
98 This operator is retained for compatibility with previous versions of
100 Do not rely on its existence; use
106 exists and its sticky bit is set.
108 True if the length of
119 exists and is readable.
123 exists and has a size greater
125 .It Fl t Ar file_descriptor
126 True if the file whose file descriptor number
129 is open and is associated with a terminal.
133 exists and its set user ID flag
138 exists and is writable.
140 indicates both that the write flag is on and that
142 resides on a read-write file system.
144 Note that this behaviour is specific to
146 When writing portable scripts, keep in mind that
147 on some systems, this test may
148 indicate only that the write flag is on.
152 exists and is executable.
154 indicates only that the execute flag is on.
157 is a directory, true indicates that
161 True if the length of
167 exists and is a symbolic link.
171 exists and its owner matches the effective user id of this process.
175 exists and its group matches the effective group id of this process.
179 exists and is a socket.
180 .It Ar file1 Fl nt Ar file2
183 exists and is newer than
185 .It Ar file1 Fl ot Ar file2
188 exists and is older than
190 .It Ar file1 Fl ef Ar file2
195 exist and refer to the same file.
207 .It Ar s1 Cm != Ar s2
218 based on the binary value of their characters.
224 based on the binary value of their characters.
225 .It Ar n1 Fl eq Ar n2
232 .It Ar n1 Fl ne Ar n2
239 .It Ar n1 Fl gt Ar n2
243 greater than the integer
245 .It Ar n1 Fl ge Ar n2
249 greater than or equal to the integer
251 .It Ar n1 Fl lt Ar n2
254 is algebraically less
257 .It Ar n1 Fl le Ar n2
260 is algebraically less
261 than or equal to the integer
269 will fully dereference it and then evaluate the expression
270 against the file referenced, except for the
276 These primaries can be combined with the following operators:
278 .It Cm \&! Ar expression
282 .It Ar expression1 Fl a Ar expression2
288 .It Ar expression1 Fl o Ar expression2
294 .It Cm \&( Ar expression Cm \&)
295 True if expression is true.
300 operator has higher precedence than the
304 Some shells may provide a builtin
306 command which is similar or identical to this utility.
310 .Sh GRAMMAR AMBIGUITY
313 grammar is inherently ambiguous.
314 In order to assure a degree of consistency,
315 the cases described in the
317 section D11.2/4.62.4, standard
318 are evaluated consistently according to the rules specified in the
320 All other cases are subject to the ambiguity in the
323 In particular, only expressions containing
333 utility exits with one of the following values:
334 .Bl -tag -width indent
336 expression evaluated to true.
338 expression evaluated to false or expression was
351 utility implements a superset of the
355 Both sides are always evaluated in
359 For instance, the writable status of
361 will be tested by the following command even though the former expression
362 indicated false, which results in a gratuitous access to the file system:
363 .Dl "[ -z abc -a -w file ]"
365 .Dl "[ -z abc ] && [ -w file ]"