1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
'\" te
.\" Copyright (c) 1996 Sun Microsystems, Inc - All Rights Reserved.
.\" 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.
.\" 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.
.\" 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]
.TH TEST 1B "Apr 1, 1996"
.SH NAME
test \- condition evaluation command
.SH SYNOPSIS
.LP
.nf
\fB/usr/ucb/test\fR \fIexpression\fR
.fi
.LP
.nf
\fIexpression\fR
.fi
.SH DESCRIPTION
.sp
.LP
\fBtest\fR evaluates the expression \fIexpression\fR and, if its value is true,
sets \fB0\fR (true) exit status; otherwise, a non-zero (false) exit status is
set. \fBtest\fR also sets a non-zero exit status if there are no arguments.
When permissions are tested, the effective user \fBID\fR of the process is
used.
.sp
.LP
All operators, flags, and brackets (brackets used as shown in the second
\fBSYNOPSIS\fR line) must be separate arguments to the \fBtest\fR command;
normally these items are separated by spaces.
.SH USAGE
.SS "Primitives"
.sp
.LP
The following primitives are used to construct \fIexpression\fR:
.sp
.ne 2
.na
\fB\fB-r\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is readable.
.RE
.sp
.ne 2
.na
\fB\fB-w\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is writable.
.RE
.sp
.ne 2
.na
\fB\fB-x\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is executable.
.RE
.sp
.ne 2
.na
\fB\fB-f\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is a regular file. Alternatively, if
\fB/usr/bin/sh\fR users specify \fB/usr/ucb\fR before \fB/usr/bin\fR in their
\fBPATH\fR environment variable, then \fBtest\fR will return true if
\fIfilename\fR exists and is (\fBnot\(mia\(midirectory\fR). This is also the
default for \fB/usr/bin/csh\fR users.
.RE
.sp
.ne 2
.na
\fB\fB-d\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is a directory.
.RE
.sp
.ne 2
.na
\fB\fB-c\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is a character special file.
.RE
.sp
.ne 2
.na
\fB\fB-b\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is a block special file.
.RE
.sp
.ne 2
.na
\fB\fB-p\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and is a named pipe (fifo).
.RE
.sp
.ne 2
.na
\fB\fB-u\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and its set-user- \fBID\fR bit is set.
.RE
.sp
.ne 2
.na
\fB\fB-g\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and its set-group- \fBID\fR bit is set.
.RE
.sp
.ne 2
.na
\fB\fB-k\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and its sticky bit is set.
.RE
.sp
.ne 2
.na
\fB\fB-s\fR \fIfilename\fR\fR
.ad
.RS 16n
True if \fIfilename\fR exists and has a size greater than zero.
.RE
.sp
.ne 2
.na
\fB\fB-t\fR[ \fIfildes\fR ]\fR
.ad
.RS 16n
True if the open file whose file descriptor number is \fIfildes\fR (1 by
default) is associated with a terminal device.
.RE
.sp
.ne 2
.na
\fB\fB-z\fR \fIs1\fR\fR
.ad
.RS 16n
True if the length of string \fIs1\fR is zero.
.RE
.sp
.ne 2
.na
\fB\fB-n\fR \fIs1\fR\fR
.ad
.RS 16n
True if the length of the string \fIs1\fR is non-zero.
.RE
.sp
.ne 2
.na
\fB\fIs1\fR\fB = \fR\fIs2\fR\fR
.ad
.RS 16n
True if strings \fIs1\fR and \fIs2\fR are identical.
.RE
.sp
.ne 2
.na
\fB\fIs1\fR\fB != \fR\fIs2\fR\fR
.ad
.RS 16n
True if strings \fIs1\fR and \fIs2\fR are \fInot\fR identical.
.RE
.sp
.ne 2
.na
\fB\fIs1\fR\fR
.ad
.RS 16n
True if \fIs1\fR is \fInot\fR the null string.
.RE
.sp
.ne 2
.na
\fB\fIn1\fR\fB \(mieq \fR\fIn2\fR\fR
.ad
.RS 16n
True if the integers \fIn1\fR and \fIn2\fR are algebraically equal. Any of the
comparisons \fB\(mine\fR, \fB\(migt\fR, \fB\(mige\fR, \fB\(milt\fR, and
\fB\(mile\fR may be used in place of \fB\(mieq\fR\&.
.RE
.SS "Operators"
.sp
.LP
These primaries may be combined with the following operators:
.sp
.ne 2
.na
\fB\fB!\fR\fR
.ad
.RS 16n
Unary negation operator.
.RE
.sp
.ne 2
.na
\fB\fB-a\fR\fR
.ad
.RS 16n
Binary \fIand\fR operator.
.RE
.sp
.ne 2
.na
\fB\fB-o\fR\fR
.ad
.RS 16n
Binary \fIor\fR operator (\fB-a\fR has higher precedence than \fB-o\fR).
.RE
.sp
.ne 2
.na
\fB(\fIexpression\fR)\fR
.ad
.RS 16n
Parentheses for grouping. Notice also that parentheses are meaningful to the
shell and, therefore, must be quoted.
.RE
.SH SEE ALSO
.sp
.LP
\fBfind\fR(1), \fBsh\fR(1), \fBattributes\fR(5)
.SH NOTES
.sp
.LP
The \fBnot\(mia\(midirectory\fR alternative to the \fB-f\fR option is a
transition aid for \fBBSD\fR applications and may not be supported in future
releases.
.sp
.LP
If you test a file you own (the \fB-r\fR \fB,\fR \fB-w\fR \fB,\fR or \fB-x\fR
tests), but the permission tested does not have the \fIowner\fR bit set, a
non-zero (false) exit status will be returned even though the file may have the
\fIgroup\fR or \fIother\fR bit set for that permission. The correct exit status
will be set if you are super-user.
.sp
.LP
The \fB=\fR and \fB!=\fR operators have a higher precedence than the \fB-r\fR
through \fB-n\fR operators, and \fB=\fR and \fB!=\fR always expect arguments;
therefore, \fB=\fR and \fB!=\fR cannot be used with the \fB-r\fR through
\fB-n\fR operators.
.sp
.LP
If more than one argument follows the \fB-r\fR through \fB-n\fR operators, only
the first argument is examined; the others are ignored, unless a \fB-a\fR or a
\fB-o\fR is the second argument.
|