1 .\" $OpenBSD: test.1,v 1.30 2010/09/11 20:54:22 jmc 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: September 11 2010 $
41 .Nd condition evaluation utility
53 to true, returns a zero (true) exit status; otherwise
62 All operators and flags are separate arguments to the
65 Symbolic links are followed for all primaries except
70 The following primaries are used to construct
76 exists and is a block special
81 exists and is a character
86 exists and is a directory.
90 exists (regardless of type).
94 exists and is a regular file.
98 exists and its group matches the effective group ID of this process.
102 exists and its set-group-ID flag
107 exists and is a symbolic link.
111 exists and its sticky bit is set.
115 exists and is a symbolic link.
116 This operator is for compatibility purposes.
117 Do not rely on its existence;
122 True if the length of
128 exists and its owner matches the effective user ID of this process.
137 exists and is readable.
141 exists and is a socket.
145 exists and has a size greater
147 .It Fl t Ar file_descriptor
148 True if the file whose file descriptor number
151 (default 1) is open and is associated with a terminal.
155 exists and its set-user-ID flag
160 exists and is writable.
162 indicates only that the write flag is on.
163 The file is not writable on a read-only file
164 system even if this test indicates true.
168 exists and is executable.
170 indicates only that the execute flag is on.
173 is a directory, true indicates that
177 True if the length of
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.
202 .It Ar s1 Cm != Ar s2
208 .It Ar s1 Cm \*(Lt Ar s2
213 based on the ASCII value of their characters.
214 .It Ar s1 Cm \*(Gt Ar s2
219 based on the ASCII value of their characters.
225 .It Ar n1 Fl eq Ar n2
232 .It Ar n1 Fl ne Ar n2
239 .It Ar n1 Fl gt Ar n2
243 greater than the integer
245 .It Ar n1 Fl ge Ar n2
249 greater than or equal to the integer
251 .It Ar n1 Fl \< Ar n2
254 is algebraically less
257 .It Ar n1 Fl le Ar n2
260 is algebraically less
261 than or equal to the integer
265 These primaries can be combined with the following operators.
268 operator has higher precedence than the
272 .It Cm \&! Ar expression
276 .It Ar expression1 Fl a Ar expression2
282 .It Ar expression1 Fl o Ar expression2
288 .It Cm \&( Ar expression Cm \&)
296 utility exits with one of the following values:
298 .Bl -tag -width Ds -offset indent -compact
300 Expression evaluated to true.
302 Expression evaluated to false or expression was
307 .Sh GRAMMAR AMBIGUITY
310 grammar is inherently ambiguous.
311 In order to assure a degree of consistency,
312 the cases described in
315 are evaluated consistently according to the rules specified in the
317 All other cases are subject to the ambiguity in the
324 utility is compliant with the
338 are extensions to that specification.
341 also exists as a built-in to
343 though with a different syntax.