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