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 $
44 .Nd condition evaluation utility
53 utility evaluates the expression and, if it evaluates
54 to true, returns a zero (true) exit status; otherwise
56 If there is no expression, test also
59 All operators and flags are separate arguments to the
63 The following primaries are used to construct expression:
68 exists and is a block special
73 exists and is a character
78 exists and is a directory.
82 exists (regardless of type).
86 exists and is a regular file.
90 exists and its set group ID flag
95 exists and is a symbolic link.
96 This operator is retained for compatibility with previous versions of
98 Do not rely on its existence; use
104 exists and its sticky bit is set.
106 True if the length of
117 exists and is readable.
121 exists and has a size greater
123 .It Fl t Ar file_descriptor
124 True if the file whose file descriptor number
127 is open and is associated with a terminal.
131 exists and its set user ID flag
136 exists and is writable.
138 indicates only that the write flag is on.
139 The file is not writable on a read-only file
140 system even if this test indicates true.
144 exists and is executable.
146 indicates only that the execute flag is on.
149 is a directory, true indicates that
153 True if the length of
159 exists and is a symbolic link.
163 exists and its owner matches the effective user id of this process.
167 exists and its group matches the effective group id of this process.
171 exists and is a socket.
172 .It Ar file1 Fl nt Ar file2
175 exists and is newer than
177 .It Ar file1 Fl ot Ar file2
180 exists and is older than
182 .It Ar file1 Fl ef Ar file2
187 exist and refer to the same file.
193 .It Ar \&s\&1 Cm \&= Ar \&s\&2
199 .It Ar \&s\&1 Cm \&!= Ar \&s\&2
205 .It Ar \&s\&1 Cm \&< Ar \&s\&2
210 based on the ASCII value of their characters.
211 .It Ar \&s\&1 Cm \&> Ar \&s\&2
216 based on the ASCII value of their characters.
222 .It Ar \&n\&1 Fl \&eq Ar \&n\&2
229 .It Ar \&n\&1 Fl \&ne Ar \&n\&2
236 .It Ar \&n\&1 Fl \> Ar \&n\&2
240 greater than the integer
242 .It Ar \&n\&1 Fl \&ge Ar \&n\&2
246 greater than or equal to the integer
248 .It Ar \&n\&1 Fl \< Ar \&n\&2
251 is algebraically less
254 .It Ar \&n\&1 Fl \&le Ar \&n\&2
257 is algebraically less
258 than or equal to the integer
262 These primaries can be combined with the following operators:
264 .It Cm \&! Ar expression
268 .It Ar expression1 Fl a Ar expression2
274 .It Ar expression1 Fl o Ar expression2
280 .It Cm \&( Ns Ar expression Ns Cm \&)
281 True if expression is true.
286 operator has higher precedence than the
290 Some shells may provide a builtin
292 command which is similar or identical to this utility.
296 .Sh GRAMMAR AMBIGUITY
299 grammar is inherently ambiguous. In order to assure a degree of consistency,
300 the cases described in the
302 section D11.2/4.62.4, standard
303 are evaluated consistently according to the rules specified in the
304 standards document. All other cases are subject to the ambiguity in the
309 utility exits with one of the following values:
312 expression evaluated to true.
314 expression evaluated to false or expression was
326 utility implements a superset of the