forked from s3lase/v6shell
-
Notifications
You must be signed in to change notification settings - Fork 3
/
if.1
406 lines (404 loc) · 11.2 KB
/
if.1
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
.\"
.\" Copyright (c) 2004-2014
.\" Jeffrey Allen Neitzel <jan (at) v6shell (dot) org>.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
.\" DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
.\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" @(#)$Id$
.\"
.\" Derived from: Sixth Edition UNIX /usr/man/man1/if.1
.\"
.\" Copyright (C) Caldera International Inc. 2001-2002. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code and documentation must retain the above
.\" copyright notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed or owned by Caldera
.\" International, Inc.
.\" 4. Neither the name of Caldera International, Inc. nor the names of other
.\" contributors may be used to endorse or promote products derived from
.\" this software without specific prior written permission.
.\"
.\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
.\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
.\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" Includes content derived from:
.\" - /usr/src/bin/test/test.1
.\" $OpenBSD: test.1,v 1.30 2010/09/11 20:54:22 jmc Exp $
.\" $NetBSD: test.1,v 1.6 1995/03/21 07:04:03 cgd Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" the Institute of Electrical and Electronics Engineers, Inc.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)test.1 8.1 (Berkeley) 5/31/93
.\"
.\" Includes public domain content derived from:
.\" - /usr/src/bin/ksh/sh.1
.\" $OpenBSD: sh.1,v 1.91 2011/09/03 22:59:08 jmc Exp $
.\"
.TH IF 1 "@OSH_DATE@" "@OSH_VERSION@" "General Commands"
.SH NAME
if \- conditional command
.SH SYNOPSIS
.B if
[\fIexpression\fR [\fIcommand\fR [\fIarg ...\fR]]]
.SH DESCRIPTION
.B If
evaluates the specified
.IR expression ,
and if its value is true,
returns a zero exit status or executes
the specified
.I command
with the given arguments.
Otherwise,
it returns a non-zero exit status.
When
.I expression
is not specified,
.B if
also returns a non-zero exit status.
.PP
The following primaries are used to construct
.IR expression :
.TP 10
\fB{\fR \fIcommand\fR [\fIarg ...\fR] \fB}\fR
The specified \fIcommand\fR is executed with the
given arguments to obtain its exit status.
A zero status is \fItrue\fR;
a non-zero status is \fIfalse\fR.
.TP
.BI \-d \ file
True if \fIfile\fR exists and is a directory.
.TP
.BI \-e \ file
True if \fIfile\fR exists.
.TP
.BI \-f \ file
True if \fIfile\fR exists and is a regular file.
.TP
.BI \-h \ file
True if \fIfile\fR exists and is a symbolic link.
.TP
.BI \-r \ file
True if \fIfile\fR exists and is readable.
.TP
.BI \-s \ file
True if \fIfile\fR exists and has a size greater than zero bytes.
.TP
.BI \-t \ fildes
True if the file whose file descriptor number is
.I fildes
is open and associated with a terminal device.
.I Fildes
must be a decimal digit (0 \- 9).
.TP
.BI \-w \ file
True if \fIfile\fR exists and is writable.
.TP
.BI \-x \ file
True if \fIfile\fR exists and is executable,
or if \fIfile\fR is a searchable directory.
.TP
.IB file1 \ \-ef \ file2
True if \fIfile1\fR and \fIfile2\fR both exist and refer
to the same file (same device, same inode).
.TP
.IB file1 \ \-nt \ file2
True if \fIfile1\fR and \fIfile2\fR both exist
and last data-modification time of \fIfile1\fR
is newer than that of \fIfile2\fR.
.TP
.IB file1 \ \-ot \ file2
True if \fIfile1\fR and \fIfile2\fR both exist
and last data-modification time of \fIfile1\fR
is older than that of \fIfile2\fR.
.TP
.IB s1 \ = \ s2
True if the strings
.I s1
and
.I s2
are equal.
.TP
.IB s1 \ != \ s2
True if the strings
.I s1
and
.I s2
are not equal.
.TP
.IB s1 \ < \ s2
True if the string
.I s1
comes before
.I s2
according to their ASCII character values.
.\" according to the ASCII values
.\" of their characters.
.TP
.IB s1 \ > \ s2
True if the string
.I s1
comes after
.I s2
according to their ASCII character values.
.\" according to the ASCII values
.\" of their characters.
.TP
.IB n1 \ \-eq \ n2
True if the integers
.I n1
and
.I n2
are algebraically equal.
.TP
.IB n1 \ \-ne \ n2
True if the integers
.I n1
and
.I n2
are not algebraically equal.
.TP
.IB n1 \ \-gt \ n2
True if the integer
.I n1
is algebraically greater than the integer
.IR n2 .
.TP
.IB n1 \ \-ge \ n2
True if the integer
.I n1
is algebraically greater than
or equal to the integer
.IR n2 .
.TP
.IB n1 \ \-lt \ n2
True if the integer
.I n1
is algebraically less than the integer
.IR n2 .
.TP
.IB n1 \ \-le \ n2
True if the integer
.I n1
is algebraically less than
or equal to the integer
.IR n2 .
.PP
These primaries may also be combined
with the following operators:
.TP 10
.BI ! \ expression
unary
.I negation
operator
.TP
.IB expression1 \ \-a \ expression2
binary
.I and
operator
.TP
.IB expression1 \ \-o \ expression2
binary
.I or
operator
.TP
.BI ( \ expression \ )
parentheses for grouping
.PP
.B \-a
has higher precedence than
.BR \-o .
Notice that all of the operators and flags
are separate arguments to
.BR if .
Notice also that parentheses are meaningful
to the shell and must be escaped.
.PP
Symbolic links are followed for all
\fIfile\fR-related primaries except
.BR \-h .
.SH "EXIT STATUS"
The
.B if
command exits with one of the following values:
.TP
0
The expression was true (see below).
.TP
1
The expression was false or was not specified.
.TP
2
An error was detected.
.TP
125
The specified command was found
but did not begin with the proper
magic number or a `#!shell' sequence,
and a valid shell was not specified by
EXECSHELL
with which to execute it.
.TP
126
The specified command was found
but could not be executed.
.TP
127
The specified command was not found.
.PP
If the expression is true and if
.I command
is specified and executed,
the exit status is that of the executed
.IR command .
.SH ENVIRONMENT
Notice that the concept of `user environment'
was not defined in Sixth Edition UNIX.
Thus,
use of the following environment variables
by this port of the conditional command is an enhancement:
.TP
.B EXECSHELL
If set to a non-empty string,
the value of this variable is taken as the
path name of the shell which is invoked to
execute the specified command when it does not
begin with the proper magic number
or a `#!shell' sequence.
.TP
.B PATH
If set to a non-empty string,
the value of this variable is taken as the
sequence of directories which is used to
search for the specified command.
Notice that the
conditional command from Sixth Edition UNIX
always used the equivalent of `.:/bin:/usr/bin',
not PATH.
.SH "SEE ALSO"
goto(1),
osh(1),
sh6(1),
test(1)
.PP
Osh home page:
http://v6shell.org/
.SH COMPATIBILITY
The
.B if
command from Sixth Edition UNIX
does not support the
.BR < ,
.BR > ,
.BR \-d ,
.BR \-e ,
.BR \-f ,
.BR \-h ,
.BR \-s ,
.BR \-t ,
.BR \-x ,
.BR \-ef ,
.BR \-nt ,
.BR \-ot ,
.BR \-eq ,
.BR \-ne ,
.BR \-gt ,
.BR \-ge ,
.BR \-lt ,
and
.B \-le
operators.
.PP
In addition to supporting the above operators,
this port also differs from the original in that
the exit status returned varies according to whether
the expression is true or false,
as is the case with
.IR test (1).
.SH HISTORY
An
.B if
command
appeared as
.I /bin/if
in Third Edition UNIX.
.SH LICENSE
See either the LICENSE file which is distributed with
.B osh
or
http://v6shell.org/license/
for full details.
.SH COPYRIGHT
.nf
Copyright (c) 2004-2014
Jeffrey Allen Neitzel. All rights reserved.
Copyright (c) 2001-2002
Caldera International Inc. All rights reserved.
Copyright (c) 1985, 1989, 1991, 1993
The Regents of the University of California. All rights reserved.
.fi