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.2 2003/06/17 04:22:50 dillon 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 only that the write flag is on.
140 The file is not writable on a read-only file
141 system even if this test indicates true.
145 exists and is executable.
147 indicates only that the execute flag is on.
150 is a directory, true indicates that
154 True if the length of
160 exists and is a symbolic link.
164 exists and its owner matches the effective user id of this process.
168 exists and its group matches the effective group id of this process.
172 exists and is a socket.
173 .It Ar file1 Fl nt Ar file2
176 exists and is newer than
178 .It Ar file1 Fl ot Ar file2
181 exists and is older than
183 .It Ar file1 Fl ef Ar file2
188 exist and refer to the same file.
194 .It Ar \&s\&1 Cm \&= Ar \&s\&2
200 .It Ar \&s\&1 Cm \&!= Ar \&s\&2
206 .It Ar \&s\&1 Cm \&< Ar \&s\&2
211 based on the ASCII value of their characters.
212 .It Ar \&s\&1 Cm \&> Ar \&s\&2
217 based on the ASCII value of their characters.
223 .It Ar \&n\&1 Fl \&eq Ar \&n\&2
230 .It Ar \&n\&1 Fl \&ne Ar \&n\&2
237 .It Ar \&n\&1 Fl \> Ar \&n\&2
241 greater than the integer
243 .It Ar \&n\&1 Fl \&ge Ar \&n\&2
247 greater than or equal to the integer
249 .It Ar \&n\&1 Fl \< Ar \&n\&2
252 is algebraically less
255 .It Ar \&n\&1 Fl \&le Ar \&n\&2
258 is algebraically less
259 than or equal to the integer
263 These primaries can be combined with the following operators:
265 .It Cm \&! Ar expression
269 .It Ar expression1 Fl a Ar expression2
275 .It Ar expression1 Fl o Ar expression2
281 .It Cm \&( Ns Ar expression Ns Cm \&)
282 True if expression is true.
287 operator has higher precedence than the
291 Some shells may provide a builtin
293 command which is similar or identical to this utility.
297 .Sh GRAMMAR AMBIGUITY
300 grammar is inherently ambiguous. In order to assure a degree of consistency,
301 the cases described in the
303 section D11.2/4.62.4, standard
304 are evaluated consistently according to the rules specified in the
305 standards document. All other cases are subject to the ambiguity in the
310 utility exits with one of the following values:
313 expression evaluated to true.
315 expression evaluated to false or expression was
327 utility implements a superset of the