|
|
1.1 root 1: .ds OK [\|
2: .ds CK \|]
3: .TH SH 1
4: .CT 1 shell proc_man dirs files
5: .SH NAME
6: sh, cd, wait, whatis \- shell, the standard command programming language
7: .SH SYNOPSIS
8: .B sh
9: [
10: .B -acefiknpstuvx
11: ]
12: [
13: .I args
14: ]
15: .SH DESCRIPTION
16: .I Sh
17: is a command programming language
18: that executes commands read from a terminal
19: or a file.
20: See `Invocation' below
21: for the meaning of arguments to the shell.
22: .SS Definitions
23: A
24: .I blank
25: is a tab or a space.
26: A
27: .I name
28: is a sequence of letters, digits, or underscores beginning with a letter
29: or underscore.
30: A
31: .I parameter
32: is a name, a digit, or any of the characters
33: .BR \(** ,
34: .BR @ ,
35: .BR # ,
36: .BR ? ,
37: .BR - ,
38: .BR $ ,
39: and
40: .BR !\\^ .
41: A
42: .I word
43: is a sequence of characters and quoted strings set off by operators,
44: blanks, or newlines; see `Quoting'.
45: .SS Commands
46: A
47: .I simple-command
48: is a sequence of
49: .I words
50: separated by
51: .IR blanks .
52: The first word specifies the name of the command to
53: be executed.
54: Except as specified below,
55: the remaining words are passed as arguments
56: to the invoked command.
57: The command name is passed as argument 0; see
58: .IR exec (2).
59: The
60: .I value
61: of a simple-command is its exit status
62: if it terminates normally, or
63: .BR 0200+ status
64: if it terminates abnormally; see
65: .IR signal (2)
66: for a list of
67: status values.
68: .PP
69: A
70: .I pipeline
71: is a sequence of one or more
72: .I commands
73: separated by
74: .BR | .
75: If there is more than one command, each is run
76: in a subshell;
77: .B |
78: denotes a
79: .IR pipe (2)
80: connecting the standard output of one command to the standard input
81: of the next.
82: Each command is run as a separate process;
83: the shell waits for the last command to terminate.
84: The exit status of a pipeline is the exit status of the last command.
85: .PP
86: A
87: .I list
88: is a sequence of one or more
89: pipelines
90: separated by
91: .BR ; ,
92: .BR & ,
93: .BR && ,
94: or
95: .BR || ,
96: and terminated by
97: .B ;
98: or
99: .BR & .
100: Of these four symbols,
101: .B ;
102: and
103: .B &
104: have equal precedence,
105: which is lower than that of
106: .B &&
107: and
108: .BR || .
109: The symbols
110: .B &&
111: and
112: .B ||
113: also have equal precedence.
114: A semicolon
115: .RB ( ; )
116: causes sequential execution of the preceding pipeline; an ampersand
117: .RB ( & )
118: causes asynchronous execution of the pipeline; the shell does not
119: wait and proceeds as if the pipeline
120: had returned zero exit status.
121: The symbol
122: .B &&
123: .RB ( || )
124: causes the
125: .I list
126: following it to be executed only if the preceding
127: pipeline
128: returns a zero (non-zero) exit status.
129: One or more newlines may follow any sequencing operator
130: .RB ( "; & && ||" ).
131: .PP
132: One or more newlines may always be used in place of a single semicolon,
133: and newlines may be freely inserted after any of
134: .BR "| ; & && || ;; if do then elif else fi done while until" .
135: .PP
136: A
137: .I command
138: is either a simple-command
139: or one of the following.
140: Unless otherwise stated,
141: the value returned by a command is that of the
142: last simple-command executed in the command.
143: .PP
144: .PD 0
145: .TP
146: \f5for\fP \f2name\fP \*(OK \&\f5in\fP \f2word\fP .\|.\|. \&\f5;\fP \*(CK \
147: \f5do\fP \f2list\fP \f5;\fP \f5done\fP
148: A
149: .L for
150: command executes a
151: .I list
152: of commands once for each
153: .I word,
154: with
155: .I name
156: set to each
157: .I word
158: in turn.
159: If
160: .BI in " word"
161: .RB .\|.\|. " ;"
162: is omitted or replaced by newlines, then
163: the
164: .I list
165: is executed once for each positional parameter
166: that is set; see `Parameter Substitution'.
167: .TP
168: \f5case\fP \f2word\fP \&\f5in\fP \*(OK \f2pattern\fP \*(OK | \
169: \f2pattern\fP \*(CK .\|.\|. \&\f5)\fP \f2list\fP \&\f5;;\fP \*(CK .\|.\|. \f5esac\fP
170: A
171: .L case
172: command executes the
173: .I list
174: associated with the first
175: .I pattern
176: that matches
177: .IR word .
178: The form of the patterns is
179: the same as that used for
180: file-name generation (see `File Name Generation')
181: except that a slash, a leading dot, or a dot immediately
182: following a slash need not be matched explicitly.
183: Newlines may precede each
184: .IR pattern
185: and replace the last
186: .B ;;
187: before
188: .BR esac .
189: .TP
190: \f5if\fP \f2list\fP \&\f5then\fP \f2list\fP \*(OK \
191: \&\f5elif\fP \f2list\fP \&\f5then\fP \f2list\fP \*(CK .\|.\|. \
192: \*(OK \&\f5else\fP \f2list\fP \*(CK \&\f5f\&i\fP
193: The
194: .I list
195: following
196: .L if
197: is executed and, if it
198: returns a zero exit status, the
199: .I list
200: following
201: the first
202: .L then
203: is executed.
204: Otherwise, the
205: .I lists
206: in
207: .L elif
208: clauses are executed in turn until one returns zero status;
209: then the
210: .I list
211: following
212: the next
213: .L then
214: is executed.
215: Otherwise, the
216: .L else
217: .I list
218: is executed.
219: If no
220: .L else
221: .I list
222: or
223: .L then
224: .I list
225: is executed, then the
226: .B if
227: command returns a zero exit status.
228: .TP
229: \f5while\fP \f2list\fP \&\f5do\fP \f2list\fP \&\f5done\fP
230: A
231: .L while
232: command repeatedly executes the
233: .L while
234: .I list
235: and, if the exit status of the last command in the list is zero, executes
236: the
237: .L do
238: .IR list ;
239: otherwise the loop terminates.
240: If no commands in the
241: .L do
242: .I list
243: are executed, then the
244: .L while
245: command returns a zero exit status;
246: .L until
247: may be used in place of
248: .L while
249: to negate
250: the loop termination test.
251: .TP
252: \f5(\fP\f2list\^\f5)\fP
253: .br
254: Execute
255: .I list
256: in a sub-shell.
257: .TP
258: \f5{\fP\f2list\^\fP\f5}\fR
259: .br
260: .I list
261: is simply executed.
262: .TP
263: \f2name\fP \f5() \f2command\fP
264: Define a function
265: which is referenced by
266: .I name.
267: The body of the function
268: is the
269: .IR command .
270: The most useful form of
271: .I command
272: is a sequence of commands enclosed in braces
273: .BR "{ }" .
274: Execution of functions is described under
275: .IR Execution
276: below.
277: .PD
278: .PP
279: These words
280: are only recognized as the first word of a command and when not quoted:
281: .B
282: if then else elif fi case esac for while until do done\fR.
283: .SS Comments
284: A word beginning with
285: .B #
286: causes that word and all the following characters up to a newline
287: to be ignored.
288: .SS Command Substitution
289: The standard output from a command enclosed in
290: a pair of grave accents
291: .B ` `
292: may be used as part or all
293: of a word;
294: trailing newlines are removed.
295: .SS Parameter Substitution
296: The character
297: .B $
298: is used to introduce substitutable
299: .IR parameters .
300: There are two types of parameters,
301: positional and keyword.
302: If
303: .I parameter
304: is a digit, it is a positional parameter.
305: Positional parameters may be assigned values by
306: .BR set .
307: Keyword parameters (also known as variables)
308: may be assigned values by writing:
309: .RS
310: .PP
311: .IB name = value
312: \*(OK
313: .IB name = value
314: \*(CK .\|.\|.
315: .RE
316: .PP
317: Pattern-matching is not performed on
318: .IR value .
319: There cannot be a function and a variable with the same
320: .IR name .
321: .PP
322: .PD 0
323: .TP
324: \f5${\fP\f2parameter\^\fP\f5}\fP
325: The value, if any, of the parameter is substituted.
326: The braces are required only when
327: .I parameter
328: is followed by a letter, digit, or underscore
329: that is not to be interpreted as part of its name.
330: If
331: .I parameter
332: is
333: .B \(**
334: or
335: .BR @ ,
336: all the positional
337: parameters, starting with
338: .BR $1 ,
339: are substituted
340: (separated by spaces).
341: Parameter
342: .B $0
343: is set from argument zero when the shell
344: is invoked.
345: .TP
346: \f5${\fP\f2parameter\^\fP\f5:-\fP\f2word\^\fP\f5}\fP
347: If
348: .I parameter
349: is set and is non-null, substitute its value;
350: otherwise substitute
351: .IR word .
352: .TP
353: \f5${\fP\f2parameter\^\fP\f5:=\fP\f2word\^\fP\f5}\fP
354: If
355: .I parameter
356: is not set or is null
357: set it to
358: .IR word ;
359: the value of the parameter is substituted.
360: Positional parameters may not be assigned to
361: in this way.
362: .TP
363: \f5${\fP\f2parameter\^\fP\f5:?\fP\f2word\^\fP\f5}\fP
364: If
365: .I parameter
366: is set and is non-null, substitute its value;
367: otherwise, print
368: .I word
369: and exit from the shell.
370: If
371: .I word
372: is omitted, the message
373: ``parameter null or not set''
374: is printed.
375: .TP
376: \f5${\fP\f2parameter\^\fP\f5:+\fP\f2word\^\fP\f5}\fP
377: If
378: .I parameter
379: is set and is non-null, substitute
380: .IR word ;
381: otherwise substitute nothing.
382: .PD
383: .PP
384: In the above,
385: .I word
386: is not evaluated unless it is
387: to be used as the substituted string,
388: so that, in the following example,
389: .B pwd
390: is executed only if
391: .B d
392: is not set or is null:
393: .IP
394: .B echo ${d:-\`pwd\`}
395: .PP
396: If the colon
397: .RB ( : )
398: is omitted from the above expressions, the
399: shell only checks whether
400: .I parameter
401: is set or not.
402: .PP
403: The following
404: parameters
405: are automatically set by the shell:
406: .RS
407: .PD 0
408: .TP
409: .B #
410: The number of positional parameters in decimal.
411: .TP
412: .B -
413: Flags supplied to the shell on invocation or by
414: the
415: .B set
416: command.
417: .TP
418: .B ?
419: The decimal value returned by the last synchronously executed command;
420: see
421: .IR exit (2).
422: .TP
423: .B $
424: The process number of this shell.
425: .TP
426: .B !
427: The process number of the last background command invoked.
428: .PD
429: .RE
430: .PP
431: The following
432: parameters
433: are used by the shell:
434: .RS
435: .PD 0
436: .TP
437: .B
438: .SM HOME
439: The default argument (home directory) for the
440: .I cd
441: command.
442: .TP
443: .B
444: .SM PATH
445: The search path for commands; see `Execution'.
446: .TP
447: .B
448: .SM CDPATH
449: The search path for the
450: .I cd
451: command.
452: .TP
453: .B
454: .SM MAIL
455: If this parameter is set to the name of a mail file
456: the shell informs the user of the arrival of mail
457: in the specified file.
458: The file is inspected every three minutes.
459: .TP
460: .B
461: .SM HISTORY
462: If this parameter is set to the name of a writable file,
463: the shell appends interactive input to the file, for use by the command
464: .IR = (1).
465: .TP
466: .SM
467: .B PS1
468: Primary prompt string, by default
469: .LR $ .
470: .TP
471: .SM
472: .B PS2
473: Secondary prompt string, by default
474: .LR > .
475: .TP
476: .SM
477: .B IFS
478: Internal field separators,
479: normally space, tab, and newline.
480: .PD
481: .RE
482: .PP
483: The shell gives default values to
484: \f5\s-1PATH\s+1\fP, \f5\s-1PS1\s+1\fP, \f5\s-1PS2\s+1\fP and \f5\s-1IFS\s+1\fP.
485: .SM
486: .B HOME
487: is set by
488: .IR login (8).
489: .SS Blank Interpretation
490: After parameter and command substitution,
491: the results of substitution are scanned for internal field separator
492: characters (those found in
493: .BR \s-1IFS\s+1 )
494: and split into distinct arguments where such characters are found.
495: Explicit null arguments (\^\f5"\^"\fP or \f5\'\^\'\fP\^) are retained.
496: Implicit null arguments
497: (those resulting from
498: .I parameters
499: that have no values) are removed.
500: .SS File Name Generation
501: Following substitution, each command
502: .I word
503: is scanned for
504: the characters
505: .BR \(** ,
506: .BR ? ,
507: and
508: .BR \*(OK .
509: If one of these characters appears
510: the word is regarded as a
511: .IR pattern .
512: The word is replaced with alphabetically sorted file names that match the pattern.
513: If no file name is found that matches the pattern,
514: the word is left unchanged.
515: The directories
516: .B .
517: and
518: .B ..
519: (initially or after a
520: .BR / )
521: are only matched by patterns beginning
522: with an explicit period.
523: The character
524: .B /
525: itself must be matched explicitly.
526: .PP
527: .PD 0
528: .RS
529: .TP
530: .B \(**
531: Matches any string, including the null string.
532: .TP
533: .B ?
534: Matches any single character.
535: .TP
536: .BR \*(OK .\|.\|. \*(CK
537: Matches any one of the enclosed characters.
538: A pair of characters separated by
539: .B -
540: matches any
541: character lexically between the pair, inclusive.
542: If the first character following the opening
543: .L \*(OK
544: is a
545: .L ^
546: any character not enclosed is matched.
547: .PD
548: .RE
549: .SS Quoting
550: These characters have a special meaning to the shell
551: and terminate a word unless quoted:
552: .IP
553: .L
554: ; & ( ) | < > { }
555: newline space tab
556: .PP
557: (The characters \f5{\fP and \f5}\fP need not be quoted inside a \f5${\^}\fP construction.)
558: A character may be
559: .I quoted
560: (i.e., made to stand for itself)
561: by preceding
562: it with a
563: .BR \e .
564: The pair
565: .BR \e newline
566: is ignored.
567: All characters enclosed between a pair of single quote marks \f5\'\^\'\fP\^
568: (except a single quote)
569: are quoted.
570: Inside double quote marks
571: \f5"\^"\fP
572: parameter and command substitution occurs and
573: .B \e
574: quotes the characters
575: .BR \e ,
576: .BR \` ,
577: \f5"\fP,
578: and
579: .BR $ .
580: .B
581: "$\(**"
582: is equivalent to
583: \f5"$1 \|$2\fP \|.\|.\|.\f5"\fP,
584: whereas
585: .B
586: "$@"
587: is equivalent to
588: .B
589: "$1"\|
590: .B
591: "$2"\|
592: \&.\|.\|.\|.
593: .SS Prompting
594: When used interactively,
595: the shell prompts with the value of
596: .SM
597: .B PS1
598: before reading a command.
599: If at any time a newline is typed and further input is needed
600: to complete a command, the secondary prompt
601: (i.e., the value of
602: .BR \s-1PS2\s+1 )
603: is issued.
604: .SS Input/Output
605: Before a command is executed, its input and output
606: may be redirected using a special notation interpreted by the shell.
607: The following may appear anywhere in a simple-command
608: or may precede or follow a
609: .I command
610: and are not
611: passed on to the invoked command;
612: substitution occurs before
613: .I word
614: or
615: .I digit
616: is used:
617: .PP
618: .PD 0
619: .TP 14
620: .BI < word
621: Use file
622: .I word
623: as standard input (file descriptor 0).
624: .TP
625: .BI > word
626: Use file
627: .I word
628: as standard output (file descriptor 1).
629: If the file does not exist it is created;
630: otherwise, it is truncated to zero length.
631: .TP
632: .BI >> word
633: Use file
634: .I word
635: as standard output.
636: If the file exists output is appended to it (by first seeking to the end-of-file);
637: otherwise, the file is created.
638: .TP
639: .BI << word
640: The shell input is read up to a line that is the same as
641: .IR word ,
642: or to an end-of-file.
643: The resulting document becomes
644: the standard input.
645: If any character of
646: .I word
647: is quoted, no interpretation
648: is placed upon the characters of the document;
649: otherwise, parameter and command substitution occurs,
650: (unescaped)
651: .BR \e newline
652: is ignored,
653: and
654: .B \e
655: must be used to quote the characters
656: .BR \e ,
657: .BR $ ,
658: .BR \` ,
659: and the first character of
660: .IR word .
661: .TP
662: .BI <& digit
663: Use the file associated with file descriptor
664: .I digit
665: as standard input.
666: Similarly for the standard output using
667: .BI >& digit .
668: .TP
669: .B <&-
670: The standard input is closed.
671: Similarly for the standard output using
672: .BR >&- .
673: .PD
674: .PP
675: If any of the above is preceded by a digit,
676: the
677: file descriptor which will be associated with the file
678: is that specified
679: by the digit
680: (instead of the default 0 or 1).
681: For example:
682: .IP
683: .RB .\|.\|. " 2>&1"
684: .PP
685: associates file descriptor 2 with the file currently associated with
686: file descriptor 1.
687: .PP
688: The order in which redirections are specified is significant.
689: The shell evaluates redirections left-to-right.
690: For example:
691: .IP
692: .RB .\|.\|. " 1>xxx 2>&1"
693: .PP
694: first associates file descriptor 1 with file
695: .LR xxx ,
696: then associates file descriptor 2 with the same file as
697: descriptor 1, namely
698: .LR xxx ,
699: while
700: .IP
701: .RB .\|.\|. " 2>&1 1>xxx"
702: .PP
703: associates file descriptor 2
704: with the current value of file descriptor 1 (typically the terminal)
705: and file descriptor 1 with
706: .LR xxx .
707: .PP
708: If a command is followed by
709: .BR & ,
710: the default standard input
711: for the command
712: is the empty file
713: .BR /dev/null .
714: Otherwise, the environment for the execution of a command contains the
715: file descriptors of the invoking shell as modified by
716: input/output specifications.
717: .SS Environment
718: The
719: .I environment
720: is a list of strings, conventionally function definitions
721: and name-value pairs, that is passed to
722: an executed program in the same way as a normal argument list; see
723: .IR environ (5).
724: The shell interacts with the environment in several ways.
725: On invocation, the shell scans the environment
726: and creates a
727: parameter or function
728: for each name found,
729: giving it the corresponding value.
730: If the user modifies the value of any of these
731: parameters
732: or creates new parameters,
733: none of these affects the environment
734: unless the
735: .B export
736: command is used to bind the shell's
737: parameter
738: to the environment; see also
739: .BR "set -a" .
740: A parameter may be removed from the environment
741: with the
742: .B unset
743: command.
744: The environment seen by any executed command is thus composed
745: of any unmodified name-value pairs originally inherited by the shell,
746: minus any pairs removed by
747: .BR unset ,
748: plus any modifications or additions,
749: all of which must be noted in
750: .B export
751: commands.
752: .PP
753: The environment for any
754: .I simple-command
755: may be augmented by prefixing it with one or more assignments to
756: parameters (but not functions).
757: Thus
758: .L tabs
759: gets the same environment in both lines below,
760: but the shell has one less variable in the second.
761: .IP
762: .B (export TERM; TERM=450; cmd)
763: .br
764: .B TERM=450 cmd
765: .PP
766: If the
767: .B -k
768: flag is set,
769: .I all
770: keyword arguments are placed in the environment,
771: even if they occur after the command name.
772: .SS Signals
773: .B SIGINT
774: and
775: .B SIGQUIT
776: (see
777: .IR signal (2))
778: for an invoked
779: command are ignored if the command is followed by
780: .BR & ;
781: otherwise signals have the values
782: inherited by the shell from its parent
783: (but see also
784: the
785: .B trap
786: command below).
787: .SS Execution
788: Each time a command is executed, the above substitutions are
789: carried out.
790: If the command name matches the name of a defined function, the function is executed
791: in the shell process.
792: (Note how this differs from calling a shell script.)
793: The positional parameters
794: .BR $1 ,
795: .BR $2 ,
796: \&.\|.\|.\|.
797: are set to the arguments of the function.
798: If the command name does not match a function, but matches one of the
799: builtin commands
800: listed below, it is executed in the shell process.
801: If the command name matches neither a
802: builtin command
803: nor the name of a defined function,
804: a new process is created and an attempt is made to
805: execute the command via
806: .IR exec (2).
807: .PP
808: The shell parameter
809: .B
810: .SM PATH
811: defines the search path for
812: the directory containing the command.
813: Alternative directory names are separated by
814: a colon
815: .RB ( : ).
816: The default path is
817: .B :/bin:/usr/bin
818: (specifying the current directory,
819: .BR /bin ,
820: and
821: .BR /usr/bin ,
822: in that order).
823: Note that the current directory is specified by a null path name,
824: which can appear immediately after the equal sign
825: or between the colon delimiters anywhere else in the path list.
826: If the command name contains a \f5/\fP the search path
827: is not used.
828: Otherwise, each directory in the path is
829: searched for an executable file.
830: If the file has execute permission but is not executable by
831: .IR exec (2),
832: it is assumed to be a `shell script', a file of shell commands.
833: A sub-shell is spawned to read it.
834: A parenthesized command is also executed in
835: a sub-shell.
836: .SS Builtin Commands
837: Input/output redirection is permitted for these commands.
838: File descriptor 1 is the default output location.
839: .PP
840: .PD 0
841: .TP
842: .B :
843: No effect; the command does nothing.
844: A zero exit code is returned.
845: .br
846: .TP
847: .BI ". " file
848: Read and execute commands from
849: .I file
850: and return.
851: The search path
852: specified by
853: .B
854: .SM PATH
855: is used to find the directory containing
856: .IR file .
857: .TP
858: \f5builtin\fP \*(OK \f2command\fP \*(CK
859: Execute the builtin
860: .I command
861: (such as
862: .BR break)
863: regardless of functions defined with the same name.
864: .TP
865: \f5break\fP \*(OK \f2n\fP \*(CK
866: Exit from the enclosing \f5for\fP or
867: .B while
868: loop, if any.
869: If
870: .I n
871: is specified break
872: .I n
873: levels.
874: .TP
875: \f5continue\fP \*(OK \f2n\fP \*(CK
876: Resume the next iteration of the enclosing
877: \f5for\fP or
878: .B while
879: loop.
880: If
881: .I n
882: is specified resume at the
883: .IR n -th
884: enclosing loop.
885: .TP
886: \f5cd\fP \*(OK \f2arg\fP \*(CK
887: Change the current directory to
888: .I arg.
889: The shell
890: parameter
891: .B
892: .SM HOME
893: is the default
894: .I arg.
895: The shell parameter
896: .B
897: .SM CDPATH
898: defines the search path for
899: the directory containing
900: .IR arg .
901: Alternative directory names are separated by
902: a colon
903: .RB ( : ).
904: The current directory (default) is specified by a null path name,
905: which can appear immediately after the equal sign
906: or between the colon delimiters anywhere else in the path list.
907: If
908: .I arg
909: begins with a
910: .L /
911: the search path
912: is not used.
913: Otherwise, each directory in the path is
914: searched for
915: .I arg.
916: .TP
917: \f5eval\fP \*(OK \f2arg\fP .\|.\|. \*(CK
918: The arguments are read as input
919: to the shell
920: and the resulting command(s) executed.
921: .TP
922: \f5exec\fP \*(OK \f2arg\fP .\|.\|. \*(CK
923: The non-builtin command specified by
924: the arguments is executed in place of this shell
925: without creating a new process.
926: Input/output arguments may appear and, if no other
927: arguments are given, cause the shell
928: input/output to be modified.
929: .TP
930: \f5exit\fP \*(OK \f2n\fP \*(CK
931: Causes a shell to exit
932: with the exit status specified by
933: .IR n .
934: If
935: .I n
936: is omitted the exit status is that of the last command executed
937: (an end-of-file will also cause the shell to exit.)
938: .TP
939: \f5export\fP \*(OK \f2name\fP .\|.\|. \*(CK
940: The given
941: .I names
942: are marked
943: for automatic export to the
944: .I environment
945: of subsequently-executed commands.
946: If no arguments are given, a list of all
947: names that are exported in this shell is printed.
948: .TP
949: \f5read\fP \*(OK \f2name\fP .\|.\|. \*(CK
950: One line is read from the standard input and
951: the first
952: word is assigned to the first
953: .I name,
954: the second word
955: to the second
956: .I name,
957: etc., with leftover words assigned to the last
958: .I name.
959: The return code is 0 unless an end-of-file is encountered.
960: .TP
961: \f5return\fP \*(OK \f2n\fP \*(CK
962: Causes a function to exit with the return value specified by
963: .I n.
964: If
965: .I n
966: is omitted, the return status is that of the last command executed.
967: .TP
968: \f5set\fP \*(OK \f5--aehknptuvx\fP \*(OK \f2arg\fP .\|.\|. \*(CK \*(CK
969: .RS
970: .TP
971: .B -a
972: Mark variables which are modified or created for export.
973: .TP
974: .B -e
975: Exit immediately if a command
976: exits with a non-zero exit status.
977: .TP
978: .B -f
979: Disable file name generation
980: .TP
981: .B -k
982: All keyword arguments are placed in the environment for a command,
983: not just those that precede the command name.
984: .TP
985: .B -n
986: Read commands but do not execute them.
987: .TP
988: .B -p
989: Remove the definitions for all functions imported from the environment,
990: and set
991: .B IFS
992: to blank, tab and newline.
993: .TP
994: .B -t
995: Exit after reading and executing one command.
996: .TP
997: .B -u
998: Treat unset variables as an error when substituting.
999: .TP
1000: .B -v
1001: Print shell input lines as they are read.
1002: .TP
1003: .B -x
1004: Print commands and their arguments as they are executed.
1005: .TP
1006: .B --
1007: Do not change any of the flags; useful in setting
1008: .B $1
1009: to
1010: .BR - .
1011: .PP
1012: Using
1013: .B \+
1014: rather than
1015: .B -
1016: causes these flags to be turned off.
1017: These flags can also be used upon invocation of the shell.
1018: The current set of flags may be found in
1019: .BR $- .
1020: The remaining arguments are positional
1021: parameters and are assigned, in order, to
1022: .BR $1 ,
1023: .BR $2 ,
1024: \&.\|.\|.\|.
1025: If no arguments are given the values
1026: of all names are printed.
1027: .RE
1028: .TP
1029: \f5shift\fP \*(OK \f2n\fP \*(CK
1030: .br
1031: The positional parameters from
1032: .BI $ n\fR+1
1033: \&.\|.\|.
1034: are renamed
1035: .B $1
1036: \&.\|.\|.
1037: If
1038: .I n
1039: is not given, it is assumed to be 1.
1040: .TP
1041: \f5times\fP
1042: .br
1043: Print the accumulated user and system times for processes
1044: run from the shell.
1045: .TP
1046: \f5trap\fP \*(OK \f2arg\fP \*(CK \*(OK \f2n\fP \*(CK .\|.\|.
1047: The command
1048: .I arg
1049: is to be read and executed when the shell
1050: receives signal(s)
1051: .IR n .
1052: (Note that
1053: .I arg
1054: is scanned once when
1055: the trap is set and once when the trap
1056: is taken.)
1057: Trap commands are executed in order of signal number.
1058: Any attempt to set a trap on a signal that
1059: was ignored on entry to the current shell
1060: is ineffective.
1061: If
1062: .I arg
1063: is absent all traps
1064: .I n
1065: are reset
1066: to their original values.
1067: If
1068: .I arg
1069: is the null
1070: string this signal is ignored by the shell and by the commands
1071: it invokes.
1072: If
1073: .I n
1074: is 0 the command
1075: .I arg
1076: is executed
1077: on exit from the shell.
1078: The
1079: .B trap
1080: command
1081: with no arguments prints a list
1082: of commands associated with each signal number.
1083: .TP
1084: \f5umask\fP \*(OK \f2nnn\fP \*(CK
1085: The user file-creation mask is set to
1086: .IR nnn ;
1087: see
1088: .IR umask (2).
1089: If
1090: .I nnn
1091: is omitted, the current value of the mask is printed.
1092: .TP
1093: \f5unset\fP \*(OK \f2name\fP .\|.\|. \*(CK
1094: For each
1095: .IR name ,
1096: remove the corresponding variable or function.
1097: The variables
1098: \f5\s-1PATH\s+1\fP, \f5\s-1PS1\s+1\fP, \f5\s-1PS2\s+1\fP and \f5\s-1IFS\s+1\fP
1099: cannot be unset.
1100: .TP
1101: \f5wait\fP \*(OK \f2n\fP \*(CK
1102: Wait for the specified process and report its termination status.
1103: If
1104: .I n
1105: is not given all currently active child processes are waited for
1106: and the return code is zero.
1107: .TP
1108: \f5whatis\fP \*(OK \fIname\fP .\|.\|. \*(CK
1109: For each
1110: .IR name ,
1111: print the associated value as a parameter, function, builtin or executable
1112: binary as appropriate.
1113: In each case, the value is printed in a form that would yield the same
1114: value if typed as input to the shell itself:
1115: parameters are printed as assignments, functions as their definitions,
1116: builtins as calls to
1117: .BR builtin ,
1118: and binaries as their full pathnames.
1119: .PD
1120: .PP
1121: .SS Invocation
1122: Normally the shell reads commands from the file named in its
1123: first argument (standard input default).
1124: The remaining arguments are interpreted as position parameters; see
1125: `Parameter substitution' above.
1126: If the shell is invoked through
1127: .IR exec (2)
1128: and the first character of argument zero
1129: is
1130: .BR - ,
1131: commands are read first from
1132: .BR $HOME/.profile ,
1133: if it exists.
1134: Certain options modify this behavior:
1135: .PP
1136: .PD 0
1137: .TP 10
1138: .BI -c "\| string"
1139: Read commands from
1140: .IR string ;
1141: ignore remaining arguments.
1142: .TP
1143: .B -s
1144: Write shell output (except for builtin commands)
1145: on file descriptor 2.
1146: .TP
1147: .B -i
1148: Interactive.
1149: Ignore signal
1150: .B SIGTERM
1151: (interactive shell is immune to
1152: .BR "kill 0" ).
1153: Catch and ignore
1154: .B SIGINT
1155: .RB ( wait
1156: is interruptible).
1157: The shell always ignores
1158: .BR SIGQUIT .
1159: .PD
1160: .PP
1161: Other options are described under the
1162: .B set
1163: command above.
1164: .SH FILES
1165: .F $HOME/.profile
1166: .br
1167: .F /tmp/sh*
1168: .br
1169: .F /dev/null
1170: .SH SEE ALSO
1171: .IR = (1),
1172: .IR echo (1),
1173: .IR newgrp (1),
1174: .IR test (1),
1175: .IR dup (2),
1176: .IR exec (2),
1177: .IR fork (2),
1178: .IR pipe (2),
1179: .IR signal (2),
1180: .IR umask (2),
1181: .IR exit (2),
1182: .IR environ (5)
1183: .br
1184: B. W. Kernighan and R. Pike,
1185: .I The Unix Programming Environment,
1186: Prentice-Hall, 1984
1187: .SH DIAGNOSTICS
1188: Errors detected by the shell, such as syntax errors,
1189: cause the shell
1190: to return a non-zero exit status.
1191: If the shell is being used non-interactively
1192: execution of the shell file is abandoned.
1193: Otherwise, the shell returns the exit status of
1194: the last command executed; see also the
1195: .B exit
1196: command.
1197: .SH BUGS
1198: Errors arising from builtins terminate shell scripts.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.