Commit | Line | Data |
---|---|---|
3d51b67b | 1 | .\" @(#)sh.1 6.3 (Berkeley) %G% |
5a218bfe | 2 | .\" |
95a327d9 | 3 | .TH SH 1 "" |
5a218bfe KM |
4 | .AT 3 |
5 | .SH NAME | |
a9e94614 | 6 | sh, for, case, if, while, \fB:\fP, \fB.\fP, break, continue, cd, eval, exec, exit, export, login, read, readonly, set, shift, times, trap, umask, wait \- command language |
5a218bfe KM |
7 | .SH SYNOPSIS |
8 | .B sh | |
9 | [ | |
10 | .B \-ceiknrstuvx | |
11 | ] [ arg ] ... | |
12 | .ds OK [\| | |
13 | .ds CK \|] | |
14 | .ds LT \s-2<\s0 | |
15 | .ds GT \s-2>\s0 | |
16 | .ds LE \s-2<\s0 | |
17 | .ds ST * | |
18 | .SH DESCRIPTION | |
19 | .I Sh | |
a9e94614 KM |
20 | is a command programming language that executes commands read from a terminal |
21 | or a file. See | |
5a218bfe KM |
22 | .B invocation |
23 | for the meaning of arguments to the shell. | |
24 | .PP | |
25 | .B Commands. | |
26 | .br | |
27 | A | |
28 | .I simple-command | |
29 | is a sequence of non blank | |
30 | .I words | |
31 | separated by blanks (a blank is a | |
32 | .B tab | |
33 | or a | |
34 | .BR space ). | |
a9e94614 KM |
35 | The first word specifies the name of the command to be executed. |
36 | Except as specified below the remaining words are passed as arguments | |
5a218bfe | 37 | to the invoked command. |
a9e94614 KM |
38 | The command name is passed as argument 0 (see |
39 | .IR execve (2)). | |
5a218bfe KM |
40 | The |
41 | .I value | |
42 | of a simple-command is its exit status | |
a9e94614 KM |
43 | if it terminates normally or 200+\fIstatus\fP if it terminates abnormally (see |
44 | .IR sigvec (2) | |
45 | for a list of status values). | |
5a218bfe KM |
46 | .LP |
47 | A | |
48 | .I pipeline | |
49 | is a sequence of one or more | |
50 | .I commands | |
51 | separated by | |
52 | .B \(or. | |
a9e94614 | 53 | The standard output of each command but the last is connected by a |
5a218bfe KM |
54 | .IR pipe (2) |
55 | to the standard input of the next command. | |
56 | Each command is run as a separate process; | |
57 | the shell waits for the last command to terminate. | |
58 | .LP | |
59 | A | |
60 | .I list | |
61 | is a sequence of one or more | |
62 | .I pipelines | |
63 | separated by | |
64 | .BR ; , | |
65 | .BR & , | |
66 | .B && | |
67 | or | |
68 | .B \(or\|\(or | |
69 | and optionally terminated by | |
70 | .B ; | |
71 | or | |
72 | .BR & . | |
73 | .B ; | |
74 | and | |
75 | .B & | |
a9e94614 | 76 | have equal precedence which is lower than that of |
5a218bfe KM |
77 | .B && |
78 | and | |
79 | .BR \(or\|\(or , | |
80 | .B && | |
81 | and | |
82 | .B \(or\|\(or | |
83 | also have equal precedence. | |
a9e94614 | 84 | A semicolon causes sequential execution; an ampersand causes the preceding |
5a218bfe | 85 | .I pipeline |
a9e94614 | 86 | to be executed without waiting for it to finish. The symbol |
5a218bfe KM |
87 | .B && |
88 | .RB ( \(or\|\(or ) | |
89 | causes the | |
90 | .I list | |
91 | following to be executed only if the preceding | |
92 | .I pipeline | |
a9e94614 | 93 | returns a zero (non zero) value. Newlines may appear in a |
5a218bfe | 94 | .I list, |
a9e94614 | 95 | instead of semicolons, to delimit commands. |
5a218bfe KM |
96 | .LP |
97 | A | |
98 | .I command | |
a9e94614 | 99 | is either a simple-command or one of the following. |
5a218bfe KM |
100 | The value returned by a command is that of the |
101 | last simple-command executed in the command. | |
102 | .TP | |
103 | \fBfor \fIname\fR \*(OK\fBin \fIword\fR ...\*(CK \fBdo \fIlist \fBdone\fR | |
104 | Each time a | |
105 | .B for | |
106 | command is executed | |
107 | .I name | |
108 | is set to the next word in the | |
109 | .B for | |
c4d63d4e | 110 | word list. |
5a218bfe KM |
111 | If |
112 | .BI in \ word | |
113 | \&... | |
a9e94614 | 114 | is omitted, |
5a218bfe KM |
115 | .B |
116 | in "$@" | |
a9e94614 | 117 | is assumed. Execution ends when there are no more words in the list. |
5a218bfe KM |
118 | .TP |
119 | \fBcase \fIword \fBin\fR \*(OK\fIpattern \fR\*(OK \fB\(or \fIpattern \fR\*(CK ... \fB) \fIlist \fB;;\fR\*(CK ... \fBesac\fR | |
120 | A | |
121 | .B case | |
122 | command executes the | |
123 | .I list | |
a9e94614 | 124 | associated with the first pattern that matches |
5a218bfe | 125 | .I word. |
a9e94614 | 126 | The form of the patterns is the same as that used for file name generation. |
5a218bfe KM |
127 | .TP |
128 | \fBif \fIlist \fBthen \fIlist\fR \*(OK\fBelif \fIlist \fBthen \fIlist\fR\*(CK ... \*(OK\fBelse \fIlist\fR\*(CK \fBfi\fR | |
129 | The | |
130 | .I list | |
131 | following | |
132 | .B if | |
133 | is executed and if it returns zero the | |
134 | .I list | |
135 | following | |
136 | .B then | |
a9e94614 | 137 | is executed. Otherwise, the |
5a218bfe KM |
138 | .I list |
139 | following | |
140 | .B elif | |
a9e94614 | 141 | is executed and if its value is zero the |
5a218bfe KM |
142 | .I list |
143 | following | |
144 | .B then | |
a9e94614 | 145 | is executed. Failing that the |
5a218bfe KM |
146 | .B else |
147 | .I list | |
148 | is executed. | |
149 | .TP | |
150 | \fBwhile \fIlist\fR \*(OK\fBdo \fIlist\fR\*(CK \fBdone\fR | |
151 | A | |
152 | .B while | |
153 | command repeatedly executes the | |
154 | .B while | |
155 | .I list | |
156 | and if its value is zero executes the | |
157 | .B do | |
158 | .I list; | |
a9e94614 | 159 | otherwise the loop terminates. The value returned by a |
5a218bfe | 160 | .B while |
a9e94614 | 161 | command is that of the last executed command in the |
5a218bfe KM |
162 | .B do |
163 | .I list. | |
164 | .B until | |
165 | may be used in place of | |
166 | .B while | |
a9e94614 | 167 | to negate the loop termination test. |
5a218bfe KM |
168 | .TP |
169 | .BI ( " list " ) | |
170 | Execute | |
171 | .I list | |
172 | in a subshell. | |
173 | .TP | |
174 | .BI { " list " } | |
175 | .I list | |
176 | is simply executed. | |
177 | .LP | |
a9e94614 | 178 | The following words are only recognized as the first word of a command |
5a218bfe KM |
179 | and when not quoted. |
180 | .IP | |
181 | .B | |
182 | if then else elif fi case in esac for while until do done { } | |
183 | .PP | |
184 | .B Command substitution. | |
185 | .br | |
a9e94614 | 186 | The standard output from a command enclosed in a pair of back quotes |
5a218bfe | 187 | .RB ( \`\|\` ) |
a9e94614 | 188 | may be used as part or all of a word; trailing newlines are removed. |
5a218bfe KM |
189 | .PP |
190 | .B Parameter substitution. | |
191 | .br | |
192 | The character | |
193 | .B $ | |
a9e94614 | 194 | is used to introduce substitutable parameters. |
5a218bfe KM |
195 | Positional parameters may be assigned values by |
196 | .BR set . | |
197 | Variables may be set by writing | |
198 | .IP | |
199 | .IB name = value | |
200 | [ | |
201 | .IB name = value | |
202 | ] ... | |
203 | .TP | |
204 | $\fB\|{\fIparameter\fB\|}\fR | |
205 | A | |
206 | .I parameter | |
207 | is a sequence of letters, digits or underscores (a | |
208 | .IR name ), | |
a9e94614 | 209 | a digit, or any of the characters |
5a218bfe KM |
210 | .B |
211 | * @ # ? \- $ !\|. | |
212 | The value, if any, of the parameter is substituted. | |
213 | The braces are required only when | |
214 | .I parameter | |
215 | is followed by a letter, digit, or underscore | |
a9e94614 | 216 | that is not to be interpreted as part of its name. If |
5a218bfe | 217 | .I parameter |
a9e94614 | 218 | is a digit, it is a positional parameter. If |
5a218bfe KM |
219 | .I parameter |
220 | is | |
221 | .BR * " or" " @" | |
a9e94614 | 222 | then all the positional parameters, starting with |
5a218bfe KM |
223 | .SM |
224 | .BR $1 , | |
a9e94614 | 225 | are substituted separated by spaces. |
5a218bfe KM |
226 | .SM |
227 | .B $0 | |
a9e94614 | 228 | is set from argument zero when the shell is invoked. |
5a218bfe KM |
229 | .TP |
230 | $\fB\|{\fIparameter\|\-word\|\fB}\fR | |
231 | If | |
232 | .I parameter | |
a9e94614 | 233 | is set, substitute its value; otherwise substitute |
5a218bfe KM |
234 | .I word. |
235 | .TP | |
236 | $\fB\|{\fIparameter\|\(eq\|word\|\fB}\fR | |
237 | If | |
238 | .I parameter | |
a9e94614 | 239 | is not set, set it to |
5a218bfe KM |
240 | .I word; |
241 | the value of the parameter is then substituted. | |
a9e94614 | 242 | Positional parameters may not be assigned to in this way. |
5a218bfe KM |
243 | .TP |
244 | $\fB\|{\fIparameter\|?\|word\|\fB}\fR | |
245 | If | |
246 | .I parameter | |
a9e94614 | 247 | is set, substitute its value; otherwise, print |
5a218bfe | 248 | .I word |
a9e94614 | 249 | and exit from the shell. If |
5a218bfe | 250 | .I word |
a9e94614 | 251 | is omitted, a standard message is printed. |
5a218bfe KM |
252 | .TP |
253 | $\fB\|{\fIparameter\|\(plword\|\fB}\fR | |
254 | If | |
255 | .I parameter | |
a9e94614 | 256 | is set, substitute |
5a218bfe KM |
257 | .I word; |
258 | otherwise substitute nothing. | |
259 | .LP | |
260 | In the above | |
261 | .I word | |
a9e94614 KM |
262 | is not evaluated unless it is to be used as the substituted string. |
263 | (So that, for example, echo ${d\-\'pwd\'} will only execute | |
5a218bfe KM |
264 | .I pwd |
265 | if | |
266 | .I d | |
267 | is unset.) | |
268 | .LP | |
269 | The following | |
270 | .I parameters | |
271 | are automatically set by the shell. | |
272 | .RS | |
273 | .TP | |
274 | .B # | |
275 | The number of positional parameters in decimal. | |
276 | .PD 0 | |
277 | .TP | |
278 | .B \- | |
279 | Options supplied to the shell on invocation or by | |
280 | .BR set . | |
281 | .TP | |
282 | .B ? | |
a9e94614 | 283 | The value returned by the last executed command in decimal. |
5a218bfe KM |
284 | .TP |
285 | .B $ | |
286 | The process number of this shell. | |
287 | .TP | |
288 | .B ! | |
289 | The process number of the last background command invoked. | |
290 | .PD | |
291 | .RE | |
292 | .LP | |
293 | The following | |
294 | .I parameters | |
295 | are used but not set by the shell. | |
296 | .RS | |
297 | .TP | |
298 | .B | |
299 | .SM HOME | |
300 | The default argument (home directory) for the | |
301 | .B cd | |
302 | command. | |
303 | .PD 0 | |
304 | .TP | |
305 | .B | |
306 | .SM PATH | |
307 | The search path for commands (see | |
308 | .BR execution ). | |
309 | .TP | |
310 | .B | |
311 | .SM MAIL | |
312 | If this variable is set to the name of | |
a9e94614 | 313 | a mail file, the shell informs the user of |
5a218bfe KM |
314 | the arrival of mail in the specified file. |
315 | .SM | |
316 | .TP | |
317 | .B PS1 | |
a9e94614 | 318 | Primary prompt string, by default '$ '. |
5a218bfe KM |
319 | .TP |
320 | .SM | |
321 | .B PS2 | |
a9e94614 | 322 | Secondary prompt string, by default '> '. |
5a218bfe KM |
323 | .TP |
324 | .SM | |
325 | .B IFS | |
a9e94614 | 326 | Internal field separators, normally |
5a218bfe KM |
327 | .BR space , |
328 | .BR tab , | |
329 | and | |
330 | .BR newline . | |
3d51b67b KM |
331 | .B IFS |
332 | is ignored if | |
333 | .I sh | |
334 | is running as root or if the effective user id differs from the real user id. | |
5a218bfe KM |
335 | .PD |
336 | .RE | |
337 | .PP | |
338 | .B Blank interpretation. | |
339 | .br | |
340 | After parameter and command substitution, | |
341 | any results of substitution are scanned for internal field separator | |
342 | characters (those found in | |
343 | .SM | |
344 | .BR $IFS \*S) | |
345 | and split into distinct arguments where such characters are found. | |
346 | Explicit null arguments ("" or \'\') are retained. | |
a9e94614 | 347 | Implicit null arguments (those resulting from |
5a218bfe KM |
348 | .I parameters |
349 | that have no values) are removed. | |
350 | .PP | |
351 | .B File name generation. | |
352 | .br | |
a9e94614 | 353 | Following substitution, each command word is scanned for the characters |
5a218bfe KM |
354 | .BR * , |
355 | .B ? | |
356 | and | |
357 | .B \*(OK. | |
a9e94614 KM |
358 | If one of these characters appears, the word is regarded as a pattern. |
359 | The word is replaced with alphabetically sorted file names that match the | |
360 | pattern. If no file name is found that matches the pattern, | |
361 | the word is left unchanged. The character | |
5a218bfe | 362 | .B . |
a9e94614 | 363 | at the start of a file name or immediately following a |
5a218bfe KM |
364 | .BR / , |
365 | and the character | |
366 | .BR / , | |
367 | must be matched explicitly. | |
368 | .TP | |
369 | .B \*(ST | |
370 | Matches any string, including the null string. | |
371 | .PD 0 | |
372 | .TP | |
373 | .B ? | |
374 | Matches any single character. | |
375 | .TP | |
376 | .B \*(OK...\*(CK | |
a9e94614 | 377 | Matches any one of the characters enclosed. |
5a218bfe KM |
378 | A pair of characters separated by |
379 | .B \- | |
a9e94614 | 380 | matches any character lexically between the pair. |
5a218bfe KM |
381 | .PD |
382 | .PP | |
383 | .B Quoting. | |
384 | .br | |
385 | The following characters have a special meaning to the shell | |
386 | and cause termination of a word unless quoted. | |
387 | .LP | |
388 | \fB; & ( ) \(or \*(LT \*(GT newline space tab\fP | |
389 | .LP | |
390 | A character may be | |
391 | .I quoted | |
a9e94614 | 392 | by preceding it with a |
5a218bfe KM |
393 | .B |
394 | \\\|. | |
395 | .B \\\\newline | |
396 | is ignored. | |
397 | All characters enclosed between a pair of quote marks (\fB\'\|\'\fP), | |
a9e94614 | 398 | except a single quote, are quoted. Inside double quotes (\fB"\|"\fP) |
5a218bfe KM |
399 | parameter and command substitution occurs and |
400 | .B | |
401 | \\ | |
402 | quotes the characters | |
403 | .B | |
a9e94614 | 404 | \\ \' " |
5a218bfe KM |
405 | and |
406 | .BR $ \|. | |
407 | .LP | |
408 | .B | |
409 | "$*" | |
410 | is equivalent to | |
411 | .SM | |
412 | .B | |
413 | "$1 $2 ..." | |
414 | whereas | |
415 | .br | |
416 | .B | |
417 | "$@" | |
418 | is equivalent to | |
419 | .SM | |
420 | .B | |
421 | "$1" "$2" ... . | |
422 | .PP | |
423 | .B Prompting. | |
424 | .br | |
a9e94614 | 425 | When used interactively, the shell prompts with the value of |
5a218bfe KM |
426 | .SM |
427 | PS1 | |
428 | before reading a command. | |
429 | If at any time a newline is typed and further input is needed | |
a9e94614 | 430 | to complete a command, the secondary prompt |
5a218bfe KM |
431 | .RB ( \s-2$PS2\s0 ) |
432 | is issued. | |
433 | .PP | |
434 | .B Input output. | |
435 | .br | |
436 | Before a command is executed its input and output | |
437 | may be redirected using a special notation interpreted by the shell. | |
438 | The following may appear anywhere in a simple-command | |
439 | or may precede or follow a | |
440 | .I command | |
441 | and are not passed on to the invoked command. | |
442 | Substitution occurs before | |
443 | .I word | |
444 | or | |
445 | .I digit | |
446 | is used. | |
447 | .TP | |
448 | \*(LT\fI\|word\fP | |
449 | Use file | |
450 | .I word | |
451 | as standard input (file descriptor 0). | |
452 | .PD | |
453 | .TP | |
454 | \*(GT\fI\|word\fP | |
455 | Use file | |
456 | .I word | |
457 | as standard output (file descriptor 1). | |
a9e94614 | 458 | If the file does not exist, it is created; |
5a218bfe KM |
459 | otherwise it is truncated to zero length. |
460 | .TP | |
461 | \*(GT\*(GT\fI\|word\fP | |
462 | Use file | |
463 | .I word | |
464 | as standard output. | |
a9e94614 | 465 | If the file exists, output is appended (by seeking to the end); |
5a218bfe KM |
466 | otherwise the file is created. |
467 | .TP | |
468 | \*(LT\*(LT\fI\|word\fP | |
469 | The shell input is read up to a line the same as | |
470 | .IR word , | |
471 | or end of file. | |
a9e94614 | 472 | The resulting document becomes the standard input. |
5a218bfe KM |
473 | If any character of |
474 | .I word | |
a9e94614 | 475 | is quoted, no interpretation is placed upon the characters of the document; |
5a218bfe KM |
476 | otherwise, parameter and command substitution occurs, |
477 | .B | |
478 | \\newline | |
a9e94614 | 479 | is ignored, and |
5a218bfe KM |
480 | .B |
481 | \\ | |
482 | is used to quote the characters | |
483 | .B | |
a9e94614 | 484 | \\ $ \' |
5a218bfe KM |
485 | and the first character of |
486 | .I word. | |
487 | .TP | |
488 | \*(LT\|&\|\fIdigit\fP | |
489 | The standard input is duplicated from file descriptor | |
490 | .I digit; | |
491 | see | |
492 | .IR dup (2). | |
493 | Similarly for the standard output using \*(GT\|. | |
494 | .TP | |
495 | \*(LT\|&\|\- | |
496 | The standard input is closed. | |
497 | Similarly for the standard output using \*(GT\|. | |
498 | .PD | |
499 | .LP | |
a9e94614 KM |
500 | If one of the above is preceded by a digit, the |
501 | file descriptor created is that specified by the digit | |
502 | (instead of the default 0 or 1). For example, | |
5a218bfe KM |
503 | .LP |
504 | \&... 2\*(GT&1 | |
505 | .LP | |
506 | creates file descriptor 2 to be a duplicate | |
507 | of file descriptor 1. | |
508 | .LP | |
509 | If a command is followed by | |
510 | .B & | |
a9e94614 | 511 | then the default standard input for the command is the empty file |
5a218bfe KM |
512 | (/dev/null). |
513 | Otherwise, the environment for the execution of a command contains the | |
514 | file descriptors of the invoking shell as modified by input | |
515 | output specifications. | |
516 | .PP | |
517 | .B Environment. | |
518 | .br | |
a9e94614 KM |
519 | The environment is a list of name-value pairs that is passed to |
520 | an executed program in the same way as a normal argument list; see | |
521 | .IR execve (2) | |
5a218bfe | 522 | and |
a9e94614 | 523 | .IR environ (7). |
5a218bfe | 524 | The shell interacts with the environment in several ways. |
a9e94614 | 525 | On invocation, the shell scans the environment and creates a |
5a218bfe | 526 | .I parameter |
a9e94614 | 527 | for each name found, giving it the corresponding value. |
5a218bfe KM |
528 | Executed commands inherit the same environment. |
529 | If the user modifies the values of these | |
530 | .I parameters | |
a9e94614 | 531 | or creates new ones, none of these affects the environment unless the |
5a218bfe KM |
532 | .B export |
533 | command is used to bind the shell's | |
534 | .I parameter | |
535 | to the environment. | |
536 | The environment seen by any executed command is thus composed | |
537 | of any unmodified name-value pairs originally inherited by the shell, | |
a9e94614 | 538 | plus any modifications or additions, all of which must be noted in |
5a218bfe KM |
539 | .B export |
540 | commands. | |
541 | .LP | |
542 | The environment for any | |
543 | .I simple-command | |
544 | may be augmented by prefixing it with one or more assignments to | |
545 | .I parameters. | |
546 | Thus these two lines are equivalent | |
547 | .IP | |
548 | TERM=450 cmd args | |
549 | .br | |
550 | (export TERM; TERM=450; cmd args) | |
551 | .LP | |
552 | If the | |
553 | .B \-k | |
554 | flag is set, | |
555 | .I all | |
556 | keyword arguments are placed in the environment, | |
557 | even if the occur after the command name. | |
a9e94614 | 558 | The following prints 'a=b c' and 'c': |
5a218bfe KM |
559 | .nf |
560 | echo a=b c | |
561 | set \-k | |
562 | echo a=b c | |
563 | .fi | |
564 | .PP | |
565 | .B Signals. | |
566 | .br | |
567 | The INTERRUPT and QUIT signals for an invoked | |
568 | command are ignored if the command is followed by | |
569 | .BR & ; | |
a9e94614 | 570 | otherwise signals have the values inherited by the shell from its parent. |
5a218bfe KM |
571 | (But see also |
572 | .BR trap. ) | |
573 | .PP | |
574 | .B Execution. | |
575 | .br | |
a9e94614 KM |
576 | Each time a command is executed the above substitutions are carried out. |
577 | Except for the 'special commands' listed below a new process is created and | |
5a218bfe | 578 | an attempt is made to execute the command via an |
a9e94614 | 579 | .IR execve (2). |
5a218bfe KM |
580 | .LP |
581 | The shell parameter | |
582 | .B | |
583 | .SM $PATH | |
a9e94614 KM |
584 | defines the search path for the directory containing the command. |
585 | Each alternative directory name is separated by a colon | |
5a218bfe KM |
586 | .RB ( : ). |
587 | The default path is | |
588 | .BR :/bin:/usr/bin . | |
a9e94614 KM |
589 | If the command name contains a /, the search path is not used. |
590 | Otherwise, each directory in the path is searched for an executable file. | |
5a218bfe KM |
591 | If the file has execute permission but is not an |
592 | .I a.out | |
a9e94614 | 593 | file, it is assumed to be a file containing shell commands. |
5a218bfe | 594 | A subshell (i.e., a separate process) is spawned to read it. |
a9e94614 | 595 | A parenthesized command is also executed in a subshell. |
5a218bfe KM |
596 | .PP |
597 | .B Special commands. | |
598 | .br | |
599 | The following commands are executed in the shell process | |
600 | and except where specified | |
601 | no input output redirection is permitted for such commands. | |
602 | .TP | |
3d51b67b KM |
603 | .B # |
604 | For non-interactive shells, everything following the | |
605 | .B # | |
606 | is treated as a comment, i.e. the rest of the line is ignored. | |
607 | For interactive shells, the | |
608 | .B # | |
609 | has no special effect. | |
610 | .TP | |
5a218bfe KM |
611 | .B : |
612 | No effect; the command does nothing. | |
613 | .PD 0 | |
614 | .TP | |
615 | .BI . \ file | |
616 | Read and execute commands from | |
617 | .I file | |
a9e94614 | 618 | and return. The search path |
5a218bfe KM |
619 | .B |
620 | .SM $PATH | |
621 | is used to find the directory containing | |
622 | .IR file . | |
623 | .TP | |
624 | \fBbreak\fR \*(OK\fIn\fR\*(CK | |
625 | Exit from the enclosing | |
626 | .B for | |
627 | or | |
628 | .B while | |
629 | loop, if any. | |
630 | If | |
631 | .I n | |
a9e94614 | 632 | is specified, break |
5a218bfe KM |
633 | .I n |
634 | levels. | |
635 | .TP | |
636 | \fBcontinue\fR \*(OK\fIn\fR\*(CK | |
637 | Resume the next iteration of the enclosing | |
638 | .B for | |
639 | or | |
640 | .B while | |
a9e94614 | 641 | loop. If |
5a218bfe | 642 | .I n |
a9e94614 | 643 | is specified, resume at the |
5a218bfe KM |
644 | .IR n -th |
645 | enclosing loop. | |
646 | .TP | |
647 | \fBcd\fR \*(OK\fIarg\fR\*(CK | |
648 | Change the current directory to | |
649 | .I arg. | |
a9e94614 | 650 | The shell parameter |
5a218bfe KM |
651 | .B |
652 | .SM $HOME | |
653 | is the default | |
654 | .IR arg . | |
655 | .TP | |
656 | \fBeval\fR \*(OK\fIarg \fR...\*(CK | |
a9e94614 | 657 | The arguments are read as input to the shell |
5a218bfe KM |
658 | and the resulting command(s) executed. |
659 | .TP | |
660 | \fBexec\fR \*(OK\fIarg \fR...\*(CK | |
a9e94614 | 661 | The command specified by the arguments is executed in place of this shell |
5a218bfe KM |
662 | without creating a new process. |
663 | Input output arguments may appear and if no other | |
a9e94614 | 664 | arguments are given cause the shell input output to be modified. |
5a218bfe KM |
665 | .TP |
666 | \fBexit\fR \*(OK\fIn\fR\*(CK | |
a9e94614 | 667 | Causes a non interactive shell to exit with the exit status specified by |
5a218bfe KM |
668 | .I n. |
669 | If | |
670 | .I n | |
a9e94614 | 671 | is omitted, the exit status is that of the last command executed. |
5a218bfe KM |
672 | (An end of file will also exit from the shell.) |
673 | .TP | |
674 | \fBexport\fR \*(OK\fIname\fR ...\*(CK | |
a9e94614 | 675 | The given names are marked for automatic export to the |
5a218bfe KM |
676 | .I environment |
677 | of subsequently-executed commands. | |
a9e94614 | 678 | If no arguments are given, a list of exportable names is printed. |
5a218bfe KM |
679 | .TP |
680 | \fBlogin\fR \*(OK\fIarg\fR ...\*(CK | |
a9e94614 | 681 | Equivalent to 'exec login arg ...'. |
5a218bfe KM |
682 | .TP |
683 | .BI read \ name\ ... | |
684 | One line is read from the standard input; | |
a9e94614 | 685 | successive words of the input are assigned to the variables |
5a218bfe | 686 | .I name |
a9e94614 | 687 | in order, with leftover words to the last variable. |
5a218bfe KM |
688 | The return code is 0 unless the end-of-file is encountered. |
689 | .TP | |
690 | \fBreadonly\fR \*(OK\fIname \fR...\*(CK | |
691 | The given names are marked readonly and | |
692 | the values of the these names may not be changed | |
693 | by subsequent assignment. | |
a9e94614 | 694 | If no arguments are given, a list of all readonly names is printed. |
5a218bfe KM |
695 | .TP |
696 | \fBset\fR \*(OK\fB\-eknptuvx\fR \*(OK\fIarg \fR...\*(CK\*(CK | |
697 | .RS | |
698 | .PD 0 | |
699 | .TP 3m | |
700 | .B \-e | |
a9e94614 | 701 | If non interactive, exit immediately if a command fails. |
5a218bfe KM |
702 | .TP |
703 | .B \-k | |
704 | All keyword arguments are placed in the environment for a command, | |
705 | not just those that precede the command name. | |
706 | .TP | |
707 | .B \-n | |
708 | Read commands but do not execute them. | |
709 | .TP | |
710 | .B \-t | |
711 | Exit after reading and executing one command. | |
712 | .TP | |
713 | .B \-u | |
714 | Treat unset variables as an error when substituting. | |
715 | .TP | |
716 | .B \-v | |
717 | Print shell input lines as they are read. | |
718 | .TP | |
719 | .B \-x | |
720 | Print commands and their arguments as they are executed. | |
721 | .TP | |
722 | .B \- | |
723 | Turn off the | |
724 | .B \-x | |
725 | and | |
726 | .B \-v | |
727 | options. | |
728 | .PD | |
729 | .LP | |
730 | These flags can also be used upon invocation of the shell. | |
731 | The current set of flags may be found in | |
732 | .BR $\- . | |
733 | .LP | |
734 | Remaining arguments are positional | |
735 | parameters and are assigned, in order, to | |
736 | .SM | |
737 | .BR $1 , | |
738 | .SM | |
739 | .BR $2 , | |
a9e94614 | 740 | etc. If no arguments are given, the values of all names are printed. |
5a218bfe KM |
741 | .RE |
742 | .TP | |
743 | .B shift | |
744 | The positional parameters from | |
745 | .SM | |
746 | .BR $2 ... | |
747 | are renamed | |
748 | .SM | |
749 | .BR $1 ... | |
750 | .TP | |
751 | .B times | |
a9e94614 | 752 | Print the accumulated user and system times for processes run from the shell. |
5a218bfe KM |
753 | .TP |
754 | \fBtrap\fR \*(OK\fIarg\fR\*(CK \*(OK\fIn\fR\*(CK ... | |
755 | .I Arg | |
a9e94614 | 756 | is a command to be read and executed when the shell receives signal(s) |
5a218bfe KM |
757 | .I n. |
758 | (Note that | |
759 | .I arg | |
a9e94614 KM |
760 | is scanned once when the trap is set and once when the trap is taken.) |
761 | Trap commands are executed in order of signal number. If | |
5a218bfe | 762 | .I arg |
a9e94614 | 763 | is absent, all trap(s) |
5a218bfe | 764 | .I n |
a9e94614 | 765 | are reset to their original values. |
5a218bfe KM |
766 | If |
767 | .I arg | |
768 | is the null | |
a9e94614 | 769 | string, this signal is ignored by the shell and by invoked commands. |
5a218bfe KM |
770 | If |
771 | .I n | |
a9e94614 | 772 | is 0, the command |
5a218bfe | 773 | .I arg |
a9e94614 | 774 | is executed on exit from the shell, otherwise upon receipt of signal |
5a218bfe KM |
775 | .I n |
776 | as numbered in | |
a9e94614 | 777 | .IR sigvec (2). |
5a218bfe | 778 | .I Trap |
a9e94614 | 779 | with no arguments prints a list of commands associated with each signal number. |
5a218bfe KM |
780 | .TP |
781 | \fBumask \fR[ \fInnn\fR ] | |
a9e94614 | 782 | The user file creation mask is set to the octal value |
5a218bfe KM |
783 | .I nnn |
784 | (see | |
785 | .IR umask (2)). | |
786 | If | |
787 | .I nnn | |
788 | is omitted, the current value of the mask is printed. | |
789 | .TP | |
790 | \fBwait\fP \*(OK\fIn\fP\*(CK | |
a9e94614 | 791 | Wait for the specified process and report its termination status. If |
5a218bfe | 792 | .I n |
a9e94614 KM |
793 | is not given, all currently active child processes are waited for. |
794 | The return code from this command is that of the process waited for. | |
5a218bfe KM |
795 | .PD |
796 | .LP | |
797 | .PP | |
798 | .B Invocation. | |
799 | .br | |
800 | If the first character of argument zero is | |
801 | .BR \- , | |
802 | commands are read from | |
803 | .BR \s-2$HOME\s0/.\|profile , | |
804 | if such a file exists. | |
805 | Commands are then read as described below. | |
a9e94614 | 806 | The following flags are interpreted by the shell when it is invoked. |
5a218bfe KM |
807 | .PD 0 |
808 | .TP 11n | |
809 | .BI \-c \ string | |
810 | If the | |
811 | .B \-c | |
a9e94614 | 812 | flag is present, commands are read from |
5a218bfe KM |
813 | .I string\|. |
814 | .TP 11n | |
815 | .B \-s | |
816 | If the | |
817 | .B \-s | |
a9e94614 | 818 | flag is present or if no arguments remain |
5a218bfe | 819 | then commands are read from the standard input. |
a9e94614 | 820 | Shell output is written to file descriptor 2. |
5a218bfe KM |
821 | .TP 11n |
822 | .B \-i | |
823 | If the | |
824 | .B \-i | |
825 | flag is present or | |
826 | if the shell input and output are attached to a terminal (as told by | |
827 | .IR gtty ) | |
828 | then this shell is | |
829 | .I interactive. | |
a9e94614 KM |
830 | In this case the terminate signal SIGTERM (see |
831 | .IR sigvec (2)) | |
832 | is ignored (so that 'kill 0' | |
5a218bfe | 833 | does not kill an interactive shell) and the interrupt signal |
a9e94614 | 834 | SIGINT is caught and ignored (so that |
5a218bfe | 835 | .B wait |
a9e94614 | 836 | is interruptible). |
5a218bfe KM |
837 | In all cases SIGQUIT is ignored by the shell. |
838 | .PD | |
839 | .LP | |
840 | The remaining flags and arguments are described under the | |
841 | .B set | |
842 | command. | |
843 | .SH FILES | |
844 | .RB $HOME/ . \^profile | |
845 | .br | |
846 | /tmp/sh* | |
847 | .br | |
848 | /dev/null | |
849 | .SH SEE ALSO | |
850 | csh(1), | |
851 | test(1), | |
a9e94614 KM |
852 | execve(2), |
853 | environ(7) | |
5a218bfe | 854 | .SH DIAGNOSTICS |
a9e94614 | 855 | Errors detected by the shell, such as syntax errors cause the shell |
5a218bfe KM |
856 | to return a non zero exit status. |
857 | If the shell is being used non interactively | |
858 | then execution of the shell file is abandoned. | |
859 | Otherwise, the shell returns the exit status of | |
860 | the last command executed (see also | |
861 | .BR exit ). | |
862 | .SH BUGS | |
a9e94614 KM |
863 | If \*(LT\*(LT is used to provide standard input to an asynchronous |
864 | process invoked by &, the shell gets mixed up about naming the input document. | |
5a218bfe KM |
865 | A garbage file /tmp/sh* is created, and the shell complains about |
866 | not being able to find the file by another name. |