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.7 2007/10/20 17:56:46 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,
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.
201 .It Ar \&s\&1 Cm \&= Ar \&s\&2
207 .It Ar \&s\&1 Cm \&!= Ar \&s\&2
213 .It Ar \&s\&1 Cm \&< Ar \&s\&2
218 based on the ASCII value of their characters.
219 .It Ar \&s\&1 Cm \&> Ar \&s\&2
224 based on the ASCII value of their characters.
230 .It Ar \&n\&1 Fl \&eq Ar \&n\&2
237 .It Ar \&n\&1 Fl \&ne Ar \&n\&2
244 .It Ar \&n\&1 Fl \> Ar \&n\&2
248 greater than the integer
250 .It Ar \&n\&1 Fl \&ge Ar \&n\&2
254 greater than or equal to the integer
256 .It Ar \&n\&1 Fl \< Ar \&n\&2
259 is algebraically less
262 .It Ar \&n\&1 Fl \&le Ar \&n\&2
265 is algebraically less
266 than or equal to the integer
270 These primaries can be combined with the following operators:
272 .It Cm \&! Ar expression
276 .It Ar expression1 Fl a Ar expression2
282 .It Ar expression1 Fl o Ar expression2
288 .It Cm \&( Ns Ar expression Ns Cm \&)
289 True if expression is true.
294 operator has higher precedence than the
298 Some shells may provide a builtin
300 command which is similar or identical to this utility.
304 .Sh GRAMMAR AMBIGUITY
307 grammar is inherently ambiguous. In order to assure a degree of consistency,
308 the cases described in the
310 section D11.2/4.62.4, standard
311 are evaluated consistently according to the rules specified in the
312 standards document. All other cases are subject to the ambiguity in the
317 utility exits with one of the following values:
320 expression evaluated to true.
322 expression evaluated to false or expression was
334 utility implements a superset of the