1 .\" Copyright (c) 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
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.
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
35 .\" @(#)test.1 8.1 (Berkeley) 5/31/93
36 .\" $FreeBSD: src/bin/test/test.1,v 1.11.2.5 2001/12/14 14:22:09 ru Exp $
37 .\" $DragonFly: src/bin/test/test.1,v 1.6 2006/03/01 08:08:44 swildner Exp $
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, test also
60 All operators and flags are separate arguments to the
64 The following primaries are used to construct expression:
69 exists and is a block special
74 exists and is a character
79 exists and is a directory.
83 exists (regardless of type).
87 exists and is a regular file.
91 exists and its set group ID flag
96 exists and is a symbolic link.
97 This operator is retained for compatibility with previous versions of
99 Do not rely on its existence; use
105 exists and its sticky bit is set.
107 True if the length of
118 exists and is readable.
122 exists and has a size greater
124 .It Fl t Ar file_descriptor
125 True if the file whose file descriptor number
128 is open and is associated with a terminal.
132 exists and its set user ID flag
137 exists and is writable.
139 indicates both that the write flag is on and that
141 resides on a read-write file system.
143 Note that this behaviour is specific to
145 When writing portable scripts, keep in mind that
146 on some systems, this test may
147 indicate only that the write flag is on.
151 exists and is executable.
153 indicates only that the execute flag is on.
156 is a directory, true indicates that
160 True if the length of
166 exists and is a symbolic link.
170 exists and its owner matches the effective user id of this process.
174 exists and its group matches the effective group id of this process.
178 exists and is a socket.
179 .It Ar file1 Fl nt Ar file2
182 exists and is newer than
184 .It Ar file1 Fl ot Ar file2
187 exists and is older than
189 .It Ar file1 Fl ef Ar file2
194 exist and refer to the same file.
200 .It Ar \&s\&1 Cm \&= Ar \&s\&2
206 .It Ar \&s\&1 Cm \&!= Ar \&s\&2
212 .It Ar \&s\&1 Cm \&< Ar \&s\&2
217 based on the ASCII value of their characters.
218 .It Ar \&s\&1 Cm \&> Ar \&s\&2
223 based on the ASCII value of their characters.
229 .It Ar \&n\&1 Fl \&eq Ar \&n\&2
236 .It Ar \&n\&1 Fl \&ne Ar \&n\&2
243 .It Ar \&n\&1 Fl \> Ar \&n\&2
247 greater than the integer
249 .It Ar \&n\&1 Fl \&ge Ar \&n\&2
253 greater than or equal to the integer
255 .It Ar \&n\&1 Fl \< Ar \&n\&2
258 is algebraically less
261 .It Ar \&n\&1 Fl \&le Ar \&n\&2
264 is algebraically less
265 than or equal to the integer
269 These primaries can be combined with the following operators:
271 .It Cm \&! Ar expression
275 .It Ar expression1 Fl a Ar expression2
281 .It Ar expression1 Fl o Ar expression2
287 .It Cm \&( Ns Ar expression Ns Cm \&)
288 True if expression is true.
293 operator has higher precedence than the
297 Some shells may provide a builtin
299 command which is similar or identical to this utility.
303 .Sh GRAMMAR AMBIGUITY
306 grammar is inherently ambiguous. In order to assure a degree of consistency,
307 the cases described in the
309 section D11.2/4.62.4, standard
310 are evaluated consistently according to the rules specified in the
311 standards document. All other cases are subject to the ambiguity in the
316 utility exits with one of the following values:
319 expression evaluated to true.
321 expression evaluated to false or expression was
333 utility implements a superset of the