2 .\" Copyright (c) 1996 Sun Microsystems, Inc - All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH TEST 1B "Apr 1, 1996"
8 test \- condition evaluation command
12 \fB/usr/ucb/test\fR \fIexpression\fR
23 \fBtest\fR evaluates the expression \fIexpression\fR and, if its value is true,
24 sets \fB0\fR (true) exit status; otherwise, a non-zero (false) exit status is
25 set. \fBtest\fR also sets a non-zero exit status if there are no arguments.
26 When permissions are tested, the effective user \fBID\fR of the process is
30 All operators, flags, and brackets (brackets used as shown in the second
31 \fBSYNOPSIS\fR line) must be separate arguments to the \fBtest\fR command;
32 normally these items are separated by spaces.
37 The following primitives are used to construct \fIexpression\fR:
41 \fB\fB-r\fR \fIfilename\fR\fR
44 True if \fIfilename\fR exists and is readable.
50 \fB\fB-w\fR \fIfilename\fR\fR
53 True if \fIfilename\fR exists and is writable.
59 \fB\fB-x\fR \fIfilename\fR\fR
62 True if \fIfilename\fR exists and is executable.
68 \fB\fB-f\fR \fIfilename\fR\fR
71 True if \fIfilename\fR exists and is a regular file. Alternatively, if
72 \fB/usr/bin/sh\fR users specify \fB/usr/ucb\fR before \fB/usr/bin\fR in their
73 \fBPATH\fR environment variable, then \fBtest\fR will return true if
74 \fIfilename\fR exists and is (\fBnot\(mia\(midirectory\fR). This is also the
75 default for \fB/usr/bin/csh\fR users.
81 \fB\fB-d\fR \fIfilename\fR\fR
84 True if \fIfilename\fR exists and is a directory.
90 \fB\fB-c\fR \fIfilename\fR\fR
93 True if \fIfilename\fR exists and is a character special file.
99 \fB\fB-b\fR \fIfilename\fR\fR
102 True if \fIfilename\fR exists and is a block special file.
108 \fB\fB-p\fR \fIfilename\fR\fR
111 True if \fIfilename\fR exists and is a named pipe (fifo).
117 \fB\fB-u\fR \fIfilename\fR\fR
120 True if \fIfilename\fR exists and its set-user- \fBID\fR bit is set.
126 \fB\fB-g\fR \fIfilename\fR\fR
129 True if \fIfilename\fR exists and its set-group- \fBID\fR bit is set.
135 \fB\fB-k\fR \fIfilename\fR\fR
138 True if \fIfilename\fR exists and its sticky bit is set.
144 \fB\fB-s\fR \fIfilename\fR\fR
147 True if \fIfilename\fR exists and has a size greater than zero.
153 \fB\fB-t\fR[ \fIfildes\fR ]\fR
156 True if the open file whose file descriptor number is \fIfildes\fR (1 by
157 default) is associated with a terminal device.
163 \fB\fB-z\fR \fIs1\fR\fR
166 True if the length of string \fIs1\fR is zero.
172 \fB\fB-n\fR \fIs1\fR\fR
175 True if the length of the string \fIs1\fR is non-zero.
181 \fB\fIs1\fR\fB = \fR\fIs2\fR\fR
184 True if strings \fIs1\fR and \fIs2\fR are identical.
190 \fB\fIs1\fR\fB != \fR\fIs2\fR\fR
193 True if strings \fIs1\fR and \fIs2\fR are \fInot\fR identical.
202 True if \fIs1\fR is \fInot\fR the null string.
208 \fB\fIn1\fR\fB \(mieq \fR\fIn2\fR\fR
211 True if the integers \fIn1\fR and \fIn2\fR are algebraically equal. Any of the
212 comparisons \fB\(mine\fR, \fB\(migt\fR, \fB\(mige\fR, \fB\(milt\fR, and
213 \fB\(mile\fR may be used in place of \fB\(mieq\fR\&.
219 These primaries may be combined with the following operators:
226 Unary negation operator.
235 Binary \fIand\fR operator.
244 Binary \fIor\fR operator (\fB-a\fR has higher precedence than \fB-o\fR).
250 \fB(\fIexpression\fR)\fR
253 Parentheses for grouping. Notice also that parentheses are meaningful to the
254 shell and, therefore, must be quoted.
260 \fBfind\fR(1), \fBsh\fR(1), \fBattributes\fR(5)
264 The \fBnot\(mia\(midirectory\fR alternative to the \fB-f\fR option is a
265 transition aid for \fBBSD\fR applications and may not be supported in future
269 If you test a file you own (the \fB-r\fR \fB,\fR \fB-w\fR \fB,\fR or \fB-x\fR
270 tests), but the permission tested does not have the \fIowner\fR bit set, a
271 non-zero (false) exit status will be returned even though the file may have the
272 \fIgroup\fR or \fIother\fR bit set for that permission. The correct exit status
273 will be set if you are super-user.
276 The \fB=\fR and \fB!=\fR operators have a higher precedence than the \fB-r\fR
277 through \fB-n\fR operators, and \fB=\fR and \fB!=\fR always expect arguments;
278 therefore, \fB=\fR and \fB!=\fR cannot be used with the \fB-r\fR through
282 If more than one argument follows the \fB-r\fR through \fB-n\fR operators, only
283 the first argument is examined; the others are ignored, unless a \fB-a\fR or a
284 \fB-o\fR is the second argument.