1
.\" Copyright (c) 1991, 1993
2
.\" The Regents of the University of California. All rights reserved.
3
.\" Copyright (c) 1997-2005
4
.\" Herbert Xu <herbert@gondor.apana.org.au>. 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. Neither the name of the University nor the names of its contributors
18
.\" may be used to endorse or promote products derived from this software
19
.\" without specific prior written permission.
21
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
.\" @(#)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.
96
exists and its sticky bit is set.
109
exists and is readable.
113
exists and has a size greater
115
.It Fl t Ar file_descriptor
116
True if the file whose file descriptor number
119
is open and is associated with a terminal.
123
exists and its set user ID flag
128
exists and is writable.
130
indicates only that the write flag is on.
131
The file is not writable on a read-only file
132
system even if this test indicates true.
136
exists and is executable.
138
indicates only that the execute flag is on.
141
is a directory, true indicates that
145
True if the length of
151
exists and is a symbolic link.
152
This operator is retained for compatibility with previous versions of
154
Do not rely on its existence; use
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 \&\*[Lt] Ar \&s\&2
207
based on the ASCII value of their characters.
208
.It Ar \&s\&1 Cm \&\*[Gt] Ar \&s\&2
213
based on the ASCII 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
254
These primaries can be combined with the following operators:
256
.It Cm \&! Ar expression
260
.It Ar expression1 Fl a Ar expression2
266
.It Ar expression1 Fl o Ar expression2
272
.It Cm \&( Ns Ar expression Ns Cm \&)
273
True if expression is true.
278
operator has higher precedence than the
281
.Sh GRAMMAR AMBIGUITY
284
grammar is inherently ambiguous.
285
In order to assure a degree of consistency, the cases described in
288
are evaluated consistently according to the rules specified in the
290
All other cases are subject to the ambiguity in the command semantics.
294
utility exits with one of the following values:
297
expression evaluated to true.
299
expression evaluated to false or expression was
307
utility implements a superset of the