1 .\" $OpenBSD: test.1,v 1.33 2016/08/16 18:51:25 schwarze Exp $
2 .\" $NetBSD: test.1,v 1.6 1995/03/21 07:04:03 cgd Exp $
4 .\" Copyright (c) 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" This code is derived from software contributed to Berkeley by
8 .\" the Institute of Electrical and Electronics Engineers, Inc.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
18 .\" 3. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)test.1 8.1 (Berkeley) 5/31/93
36 .Dd $Mdocdate: August 16 2016 $
42 .Nd condition evaluation utility
54 to true, returns a zero (true) exit status; otherwise
67 All operators and flags are separate arguments to the
70 Symbolic links are followed for all primaries except
75 The following primaries are used to construct
81 exists and is a block special
86 exists and is a character
91 exists and is a directory.
95 exists (regardless of type).
99 exists and is a regular file.
103 exists and its group matches the effective group ID of this process.
107 exists and its set-group-ID flag
112 exists and is a symbolic link.
116 exists and its sticky bit is set.
120 exists and is a symbolic link.
121 This operator is for compatibility purposes.
122 Do not rely on its existence;
127 True if the length of
133 exists and its owner matches the effective user ID of this process.
142 exists and is readable.
146 exists and is a socket.
150 exists and has a size greater
152 .It Fl t Ar file_descriptor
153 True if the file whose file descriptor number
156 (default 1) is open and is associated with a terminal.
160 exists and its set-user-ID flag
165 exists and is writable.
167 indicates only that the write flag is on.
168 The file is not writable on a read-only file
169 system even if this test indicates true.
173 exists and is executable.
175 indicates only that the execute flag is on.
178 is a directory, true indicates that
182 True if the length of
185 .It Ar file1 Fl nt Ar file2
188 exists and is newer than
190 .It Ar file1 Fl ot Ar file2
193 exists and is older than
195 .It Ar file1 Fl ef Ar file2
200 exist and refer to the same file.
207 .It Ar s1 Cm != Ar s2
213 .It Ar s1 Cm \*(Lt Ar s2
218 based on the ASCII value of their characters.
219 .It Ar s1 Cm \*(Gt Ar s2
224 based on the ASCII value of their characters.
230 .It Ar n1 Fl eq Ar n2
237 .It Ar n1 Fl ne Ar n2
244 .It Ar n1 Fl gt Ar n2
248 greater than the integer
250 .It Ar n1 Fl ge Ar n2
254 greater than or equal to the integer
256 .It Ar n1 Fl \< Ar n2
259 is algebraically less
262 .It Ar n1 Fl le Ar n2
265 is algebraically less
266 than or equal to the integer
270 These primaries can be combined with the following operators.
273 operator has higher precedence than the
277 .It Cm \&! Ar expression
281 .It Ar expression1 Fl a Ar expression2
287 .It Ar expression1 Fl o Ar expression2
293 .It Cm \&( Ar expression Cm \&)
301 utility exits with one of the following values:
303 .Bl -tag -width Ds -offset indent -compact
305 Expression evaluated to true.
307 Expression evaluated to false or expression was
312 .Sh GRAMMAR AMBIGUITY
315 grammar is inherently ambiguous.
316 In order to assure a degree of consistency,
317 the cases described in
320 are evaluated consistently according to the rules specified in the
322 All other cases are subject to the ambiguity in the
329 utility is compliant with the
343 are extensions to that specification.
352 as part of X/Open System Interfaces and obsolete.
355 also exists as a built-in to
357 though with a different syntax.