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
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, test also
56 All operators and flags are separate arguments to the
60 The following primaries are used to construct expression:
65 exists and is a block special
70 exists and is a character
75 exists and is a directory.
79 exists (regardless of type).
83 exists and is a regular file.
87 exists and its set group ID flag
92 exists and is a symbolic link.
93 This operator is retained for compatibility with previous versions of
95 Do not rely on its existence; use
101 exists and its sticky bit is set.
103 True if the length of
114 exists and is readable.
118 exists and has a size greater
120 .It Fl t Ar file_descriptor
121 True if the file whose file descriptor number
124 is open and is associated with a terminal.
128 exists and its set user ID flag
133 exists and is writable.
135 indicates only that the write flag is on.
136 The file is not writable on a read-only file
137 system even if this test indicates true.
141 exists and is executable.
143 indicates only that the execute flag is on.
146 is a directory, true indicates that
150 True if the length of
156 exists and is a symbolic link.
160 exists and its owner matches the effective user id of this process.
164 exists and its group matches the effective group id of this process.
168 exists and is a socket.
169 .It Ar file1 Fl nt Ar file2
172 exists and is newer than
174 .It Ar file1 Fl ot Ar file2
177 exists and is older than
179 .It Ar file1 Fl ef Ar file2
184 exist and refer to the same file.
190 .It Ar \&s\&1 Cm \&= Ar \&s\&2
196 .It Ar \&s\&1 Cm \&!= Ar \&s\&2
202 .It Ar \&s\&1 Cm \&< Ar \&s\&2
207 based on the binary value of their characters.
208 .It Ar \&s\&1 Cm \&> Ar \&s\&2
213 based on the binary value of their characters.
214 .It Ar \&n\&1 Fl \&eq Ar \&n\&2
221 .It Ar \&n\&1 Fl \&ne Ar \&n\&2
228 .It Ar \&n\&1 Fl \> Ar \&n\&2
232 greater than the integer
234 .It Ar \&n\&1 Fl \&ge Ar \&n\&2
238 greater than or equal to the integer
240 .It Ar \&n\&1 Fl \< Ar \&n\&2
243 is algebraically less
246 .It Ar \&n\&1 Fl \&le Ar \&n\&2
249 is algebraically less
250 than or equal to the integer
258 will fully dereference it and then evaluate the expression
259 against the file referenced, except for the
265 These primaries can be combined with the following operators:
267 .It Cm \&! Ar expression
271 .It Ar expression1 Fl a Ar expression2
277 .It Ar expression1 Fl o Ar expression2
283 .It Cm \&( Ns Ar expression Ns Cm \&)
284 True if expression is true.
289 operator has higher precedence than the
293 Some shells may provide a builtin
295 command which is similar or identical to this utility.
299 .Sh GRAMMAR AMBIGUITY
302 grammar is inherently ambiguous.
303 In order to assure a degree of consistency,
304 the cases described in the
306 section D11.2/4.62.4, standard
307 are evaluated consistently according to the rules specified in the
309 All other cases are subject to the ambiguity in the
314 utility exits with one of the following values:
317 expression evaluated to true.
319 expression evaluated to false or expression was
332 utility implements a superset of the