1 .\" $NetBSD: test.1,v 1.10 1997/11/12 00:48:21 mrg Exp $
3 .\" Copyright (c) 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" the Institute of Electrical and Electronics Engineers, Inc.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\" must display the following acknowledgement:
19 .\" This product includes software developed by the University of
20 .\" California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\" may be used to endorse or promote products derived from this software
23 .\" without specific prior written permission.
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 .\" @(#)test.1 8.1 (Berkeley) 5/31/93
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
98 this program. 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
289 .Sh GRAMMAR AMBIGUITY
292 grammar is inherently ambiguous. In order to assure a degree of consistency,
293 the cases described in
296 are evaluated consistently according to the rules specified in the
297 standards document. All other cases are subject to the ambiguity in the
302 utility exits with one of the following values:
305 expression evaluated to true.
307 expression evaluated to false or expression was
315 utility implements a superset of the