Commit | Line | Data |
---|---|---|
362b077f C |
1 | |
2 | ||
3 | ||
4 | SH(1) UNIX Programmer's Manual SH(1) | |
5 | ||
6 | ||
7 | ||
8 | N\bNA\bAM\bME\bE | |
9 | sh, for, case, if, while, :\b:, .\b., break, continue, cd, eval, | |
10 | exec, exit, export, login, read, readonly, set, shift, | |
11 | times, trap, umask, wait - command language | |
12 | ||
13 | S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS | |
14 | s\bsh\bh [ -\b-c\bce\bei\bik\bkn\bnr\brs\bst\btu\buv\bvx\bx ] [ arg ] ... | |
15 | ||
16 | D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN | |
17 | _\bS_\bh is a command programming language that executes commands | |
18 | read from a terminal or a file. See i\bin\bnv\bvo\boc\bca\bat\bti\bio\bon\bn for the | |
19 | meaning of arguments to the shell. | |
20 | ||
21 | C\bCo\bom\bmm\bma\ban\bnd\bds\bs.\b. | |
22 | A _\bs_\bi_\bm_\bp_\bl_\be-_\bc_\bo_\bm_\bm_\ba_\bn_\bd is a sequence of non blank _\bw_\bo_\br_\bd_\bs separated | |
23 | by blanks (a blank is a t\bta\bab\bb or a s\bsp\bpa\bac\bce\be). The first word | |
24 | specifies the name of the command to be executed. Except as | |
25 | specified below the remaining words are passed as arguments | |
26 | to the invoked command. The command name is passed as argu- | |
27 | ment 0 (see _\be_\bx_\be_\bc_\bv_\be(2)). The _\bv_\ba_\bl_\bu_\be of a simple-command is | |
28 | its exit status if it terminates normally or 200+_\bs_\bt_\ba_\bt_\bu_\bs if | |
29 | it terminates abnormally (see _\bs_\bi_\bg_\bv_\be_\bc(2) for a list of status | |
30 | values). | |
31 | ||
32 | A _\bp_\bi_\bp_\be_\bl_\bi_\bn_\be is a sequence of one or more _\bc_\bo_\bm_\bm_\ba_\bn_\bd_\bs separated | |
33 | by |\b|.\b. The standard output of each command but the last is | |
34 | connected by a _\bp_\bi_\bp_\be(2) to the standard input of the next | |
35 | command. Each command is run as a separate process; the | |
36 | shell waits for the last command to terminate. | |
37 | ||
38 | A _\bl_\bi_\bs_\bt is a sequence of one or more _\bp_\bi_\bp_\be_\bl_\bi_\bn_\be_\bs separated by | |
39 | ;\b;, &\b&, &\b&&\b& or |\b||\b| and optionally terminated by ;\b; or &\b&. ;\b; and &\b& | |
40 | have equal precedence which is lower than that of &\b&&\b& and |\b||\b|, | |
41 | &\b&&\b& and |\b||\b| also have equal precedence. A semicolon causes | |
42 | sequential execution; an ampersand causes the preceding | |
43 | _\bp_\bi_\bp_\be_\bl_\bi_\bn_\be to be executed without waiting for it to finish. | |
44 | The symbol &\b&&\b& (|\b||\b|) causes the _\bl_\bi_\bs_\bt following to be executed | |
45 | only if the preceding _\bp_\bi_\bp_\be_\bl_\bi_\bn_\be returns a zero (non zero) | |
46 | value. Newlines may appear in a _\bl_\bi_\bs_\bt, instead of semi- | |
47 | colons, to delimit commands. | |
48 | ||
49 | A _\bc_\bo_\bm_\bm_\ba_\bn_\bd is either a simple-command or one of the follow- | |
50 | ing. The value returned by a command is that of the last | |
51 | simple-command executed in the command. | |
52 | ||
53 | f\bfo\bor\br _\bn_\ba_\bm_\be [i\bin\bn _\bw_\bo_\br_\bd ...] d\bdo\bo _\bl_\bi_\bs_\bt d\bdo\bon\bne\be | |
54 | Each time a f\bfo\bor\br command is executed _\bn_\ba_\bm_\be is set to the | |
55 | next word in the f\bfo\bor\br word list. If i\bin\bn _\bw_\bo_\br_\bd ... is | |
56 | omitted, i\bin\bn "\b"$\b$@\b@"\b" is assumed. Execution ends when there | |
57 | are no more words in the list. | |
58 | ||
59 | c\bca\bas\bse\be _\bw_\bo_\br_\bd i\bin\bn [_\bp_\ba_\bt_\bt_\be_\br_\bn [ |\b| _\bp_\ba_\bt_\bt_\be_\br_\bn ] ... )\b) _\bl_\bi_\bs_\bt ;\b;;\b;] ... e\bes\bsa\bac\bc | |
60 | ||
61 | ||
62 | ||
63 | Printed 7/9/88 May 5, 1986 1 | |
64 | ||
65 | ||
66 | ||
67 | ||
68 | ||
69 | ||
70 | SH(1) UNIX Programmer's Manual SH(1) | |
71 | ||
72 | ||
73 | ||
74 | A c\bca\bas\bse\be command executes the _\bl_\bi_\bs_\bt associated with the | |
75 | first pattern that matches _\bw_\bo_\br_\bd. The form of the pat- | |
76 | terns is the same as that used for file name genera- | |
77 | tion. | |
78 | ||
79 | i\bif\bf _\bl_\bi_\bs_\bt t\bth\bhe\ben\bn _\bl_\bi_\bs_\bt [e\bel\bli\bif\bf _\bl_\bi_\bs_\bt t\bth\bhe\ben\bn _\bl_\bi_\bs_\bt] ... [e\bel\bls\bse\be _\bl_\bi_\bs_\bt] f\bfi\bi | |
80 | The _\bl_\bi_\bs_\bt following i\bif\bf is executed and if it returns | |
81 | zero the _\bl_\bi_\bs_\bt following t\bth\bhe\ben\bn is executed. Otherwise, | |
82 | the _\bl_\bi_\bs_\bt following e\bel\bli\bif\bf is executed and if its value is | |
83 | zero the _\bl_\bi_\bs_\bt following t\bth\bhe\ben\bn is executed. Failing that | |
84 | the e\bel\bls\bse\be _\bl_\bi_\bs_\bt is executed. | |
85 | ||
86 | w\bwh\bhi\bil\ble\be _\bl_\bi_\bs_\bt [d\bdo\bo _\bl_\bi_\bs_\bt] d\bdo\bon\bne\be | |
87 | A w\bwh\bhi\bil\ble\be command repeatedly executes the w\bwh\bhi\bil\ble\be _\bl_\bi_\bs_\bt and | |
88 | if its value is zero executes the d\bdo\bo _\bl_\bi_\bs_\bt; otherwise | |
89 | the loop terminates. The value returned by a w\bwh\bhi\bil\ble\be | |
90 | command is that of the last executed command in the d\bdo\bo | |
91 | _\bl_\bi_\bs_\bt. u\bun\bnt\bti\bil\bl may be used in place of w\bwh\bhi\bil\ble\be to negate the | |
92 | loop termination test. | |
93 | ||
94 | (\b( _\bl_\bi_\bs_\bt )\b) | |
95 | Execute _\bl_\bi_\bs_\bt in a subshell. | |
96 | ||
97 | {\b{ _\bl_\bi_\bs_\bt }\b} | |
98 | _\bl_\bi_\bs_\bt is simply executed. | |
99 | ||
100 | The following words are only recognized as the first word of | |
101 | a command and when not quoted. | |
102 | ||
103 | i\bif\bf t\bth\bhe\ben\bn e\bel\bls\bse\be e\bel\bli\bif\bf f\bfi\bi c\bca\bas\bse\be i\bin\bn e\bes\bsa\bac\bc f\bfo\bor\br w\bwh\bhi\bil\ble\be u\bun\bnt\bti\bil\bl d\bdo\bo | |
104 | d\bdo\bon\bne\be {\b{ }\b} | |
105 | ||
106 | C\bCo\bom\bmm\bma\ban\bnd\bd s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn.\b. | |
107 | The standard output from a command enclosed in a pair of | |
108 | back quotes (`\b``\b`) may be used as part or all of a word; | |
109 | trailing newlines are removed. | |
110 | ||
111 | P\bPa\bar\bra\bam\bme\bet\bte\ber\br s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn.\b. | |
112 | The character $\b$ is used to introduce substitutable parame- | |
113 | ters. Positional parameters may be assigned values by s\bse\bet\bt. | |
114 | Variables may be set by writing | |
115 | ||
116 | _\bn_\ba_\bm_\be=\b=_\bv_\ba_\bl_\bu_\be [ _\bn_\ba_\bm_\be=\b=_\bv_\ba_\bl_\bu_\be ] ... | |
117 | ||
118 | ${\b{_\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br}\b} | |
119 | A _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br is a sequence of letters, digits or under- | |
120 | scores (a _\bn_\ba_\bm_\be), a digit, or any of the characters *\b* @\b@ | |
121 | #\b# ?\b? -\b- $\b$ !\b!.\b. The value, if any, of the parameter is sub- | |
122 | stituted. The braces are required only when _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br | |
123 | is followed by a letter, digit, or underscore that is | |
124 | not to be interpreted as part of its name. If _\bp_\ba_\br_\ba_\bm_\be_\b- | |
125 | _\bt_\be_\br is a digit, it is a positional parameter. If | |
126 | ||
127 | ||
128 | ||
129 | Printed 7/9/88 May 5, 1986 2 | |
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | SH(1) UNIX Programmer's Manual SH(1) | |
137 | ||
138 | ||
139 | ||
140 | _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br is *\b* or @\b@ then all the positional parameters, | |
141 | starting with $\b$1\b1, are substituted separated by spaces. | |
142 | $\b$0\b0 is set from argument zero when the shell is invoked. | |
143 | ||
144 | ${\b{_\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br-_\bw_\bo_\br_\bd}\b} | |
145 | If _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br is set, substitute its value; otherwise | |
146 | substitute _\bw_\bo_\br_\bd. | |
147 | ||
148 | ${\b{_\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br=_\bw_\bo_\br_\bd}\b} | |
149 | If _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br is not set, set it to _\bw_\bo_\br_\bd; the value of | |
150 | the parameter is then substituted. Positional parame- | |
151 | ters may not be assigned to in this way. | |
152 | ||
153 | ${\b{_\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br?_\bw_\bo_\br_\bd}\b} | |
154 | If _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br is set, substitute its value; otherwise, | |
155 | print _\bw_\bo_\br_\bd and exit from the shell. If _\bw_\bo_\br_\bd is omit- | |
156 | ted, a standard message is printed. | |
157 | ||
158 | ${\b{_\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br+_\bw_\bo_\br_\bd}\b} | |
159 | If _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br is set, substitute _\bw_\bo_\br_\bd; otherwise substi- | |
160 | tute nothing. | |
161 | ||
162 | In the above _\bw_\bo_\br_\bd is not evaluated unless it is to be used | |
163 | as the substituted string. (So that, for example, echo | |
164 | ${d-'pwd'} will only execute _\bp_\bw_\bd if _\bd is unset.) | |
165 | ||
166 | The following _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br_\bs are automatically set by the shell. | |
167 | ||
168 | #\b# The number of positional parameters in decimal. | |
169 | -\b- Options supplied to the shell on invocation or by | |
170 | s\bse\bet\bt. | |
171 | ?\b? The value returned by the last executed command in | |
172 | decimal. | |
173 | $\b$ The process number of this shell. | |
174 | !\b! The process number of the last background command | |
175 | invoked. | |
176 | ||
177 | The following _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br_\bs are used but not set by the shell. | |
178 | ||
179 | H\bHO\bOM\bME\bE The default argument (home directory) for the c\bcd\bd | |
180 | command. | |
181 | P\bPA\bAT\bTH\bH The search path for commands (see e\bex\bxe\bec\bcu\but\bti\bio\bon\bn). | |
182 | M\bMA\bAI\bIL\bL If this variable is set to the name of a mail | |
183 | file, the shell informs the user of the arrival of | |
184 | mail in the specified file. | |
185 | P\bPS\bS1\b1 Primary prompt string, by default '$ '. | |
186 | P\bPS\bS2\b2 Secondary prompt string, by default '> '. | |
187 | I\bIF\bFS\bS Internal field separators, normally s\bsp\bpa\bac\bce\be, t\bta\bab\bb, | |
188 | and n\bne\bew\bwl\bli\bin\bne\be. I\bIF\bFS\bS is ignored if _\bs_\bh is running as | |
189 | root or if the effective user id differs from the | |
190 | real user id. | |
191 | ||
192 | ||
193 | ||
194 | ||
195 | Printed 7/9/88 May 5, 1986 3 | |
196 | ||
197 | ||
198 | ||
199 | ||
200 | ||
201 | ||
202 | SH(1) UNIX Programmer's Manual SH(1) | |
203 | ||
204 | ||
205 | ||
206 | B\bBl\bla\ban\bnk\bk i\bin\bnt\bte\ber\brp\bpr\bre\bet\bta\bat\bti\bio\bon\bn.\b. | |
207 | After parameter and command substitution, any results of | |
208 | substitution are scanned for internal field separator char- | |
209 | acters (those found in $\b$I\bIF\bFS\bS) and split into distinct argu- | |
210 | ments where such characters are found. Explicit null argu- | |
211 | ments ("" or '') are retained. Implicit null arguments | |
212 | (those resulting from _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br_\bs that have no values) are | |
213 | removed. | |
214 | ||
215 | F\bFi\bil\ble\be n\bna\bam\bme\be g\bge\ben\bne\ber\bra\bat\bti\bio\bon\bn.\b. | |
216 | Following substitution, each command word is scanned for the | |
217 | characters *\b*, ?\b? and [\b[.\b. If one of these characters appears, | |
218 | the word is regarded as a pattern. The word is replaced | |
219 | with alphabetically sorted file names that match the pat- | |
220 | tern. If no file name is found that matches the pattern, | |
221 | the word is left unchanged. The character .\b. at the start of | |
222 | a file name or immediately following a /\b/, and the character | |
223 | /\b/, must be matched explicitly. | |
224 | ||
225 | *\b* Matches any string, including the null string. | |
226 | ?\b? Matches any single character. | |
227 | [\b[.\b..\b..\b.]\b] | |
228 | Matches any one of the characters enclosed. A pair of | |
229 | characters separated by -\b- matches any character lexi- | |
230 | cally between the pair. | |
231 | ||
232 | Q\bQu\buo\bot\bti\bin\bng\bg.\b. | |
233 | The following characters have a special meaning to the shell | |
234 | and cause termination of a word unless quoted. | |
235 | ||
236 | ;\b; &\b& (\b( )\b) |\b| <\b< >\b> n\bne\bew\bwl\bli\bin\bne\be s\bsp\bpa\bac\bce\be t\bta\bab\bb | |
237 | ||
238 | A character may be _\bq_\bu_\bo_\bt_\be_\bd by preceding it with a \\b\.\b. \\b\n\bne\bew\bw-\b- | |
239 | l\bli\bin\bne\be is ignored. All characters enclosed between a pair of | |
240 | quote marks ('\b''\b'), except a single quote, are quoted. Inside | |
241 | double quotes ("\b""\b") parameter and command substitution occurs | |
242 | and \\b\ quotes the characters \\b\ '\b' "\b" and $\b$. | |
243 | ||
244 | "\b"$\b$*\b*"\b" is equivalent to "\b"$\b$1\b1 $\b$2\b2 .\b..\b..\b."\b" whereas | |
245 | "\b"$\b$@\b@"\b" is equivalent to "\b"$\b$1\b1"\b" "\b"$\b$2\b2"\b" .\b..\b..\b. .\b. | |
246 | ||
247 | P\bPr\bro\bom\bmp\bpt\bti\bin\bng\bg.\b. | |
248 | When used interactively, the shell prompts with the value of | |
249 | PS1 before reading a command. If at any time a newline is | |
250 | typed and further input is needed to complete a command, the | |
251 | secondary prompt ($\b$P\bPS\bS2\b2) is issued. | |
252 | ||
253 | I\bIn\bnp\bpu\but\bt o\bou\but\btp\bpu\but\bt.\b. | |
254 | Before a command is executed its input and output may be | |
255 | redirected using a special notation interpreted by the | |
256 | shell. The following may appear anywhere in a simple- | |
257 | command or may precede or follow a _\bc_\bo_\bm_\bm_\ba_\bn_\bd and are not | |
258 | ||
259 | ||
260 | ||
261 | Printed 7/9/88 May 5, 1986 4 | |
262 | ||
263 | ||
264 | ||
265 | ||
266 | ||
267 | ||
268 | SH(1) UNIX Programmer's Manual SH(1) | |
269 | ||
270 | ||
271 | ||
272 | passed on to the invoked command. Substitution occurs | |
273 | before _\bw_\bo_\br_\bd or _\bd_\bi_\bg_\bi_\bt is used. | |
274 | ||
275 | <_\bw_\bo_\br_\bd | |
276 | Use file _\bw_\bo_\br_\bd as standard input (file descriptor 0). | |
277 | ||
278 | >_\bw_\bo_\br_\bd | |
279 | Use file _\bw_\bo_\br_\bd as standard output (file descriptor 1). | |
280 | If the file does not exist, it is created; otherwise it | |
281 | is truncated to zero length. | |
282 | ||
283 | >>_\bw_\bo_\br_\bd | |
284 | Use file _\bw_\bo_\br_\bd as standard output. If the file exists, | |
285 | output is appended (by seeking to the end); otherwise | |
286 | the file is created. | |
287 | ||
288 | <<_\bw_\bo_\br_\bd | |
289 | The shell input is read up to a line the same as _\bw_\bo_\br_\bd, | |
290 | or end of file. The resulting document becomes the | |
291 | standard input. If any character of _\bw_\bo_\br_\bd is quoted, no | |
292 | interpretation is placed upon the characters of the | |
293 | document; otherwise, parameter and command substitution | |
294 | occurs, \\b\n\bne\bew\bwl\bli\bin\bne\be is ignored, and \\b\ is used to quote the | |
295 | characters \\b\ $\b$ '\b' and the first character of _\bw_\bo_\br_\bd. | |
296 | ||
297 | <&_\bd_\bi_\bg_\bi_\bt | |
298 | The standard input is duplicated from file descriptor | |
299 | _\bd_\bi_\bg_\bi_\bt; see _\bd_\bu_\bp(2). Similarly for the standard output | |
300 | using >. | |
301 | ||
302 | <&- The standard input is closed. Similarly for the stan- | |
303 | dard output using >. | |
304 | ||
305 | If one of the above is preceded by a digit, the file | |
306 | descriptor created is that specified by the digit (instead | |
307 | of the default 0 or 1). For example, | |
308 | ||
309 | ... 2>&1 | |
310 | ||
311 | creates file descriptor 2 to be a duplicate of file descrip- | |
312 | tor 1. | |
313 | ||
314 | If a command is followed by &\b& then the default standard | |
315 | input for the command is the empty file (/dev/null). Other- | |
316 | wise, the environment for the execution of a command con- | |
317 | tains the file descriptors of the invoking shell as modified | |
318 | by input output specifications. | |
319 | ||
320 | E\bEn\bnv\bvi\bir\bro\bon\bnm\bme\ben\bnt\bt.\b. | |
321 | The environment is a list of name-value pairs that is passed | |
322 | to an executed program in the same way as a normal argument | |
323 | list; see _\be_\bx_\be_\bc_\bv_\be(2) and _\be_\bn_\bv_\bi_\br_\bo_\bn(7). The shell interacts | |
324 | ||
325 | ||
326 | ||
327 | Printed 7/9/88 May 5, 1986 5 | |
328 | ||
329 | ||
330 | ||
331 | ||
332 | ||
333 | ||
334 | SH(1) UNIX Programmer's Manual SH(1) | |
335 | ||
336 | ||
337 | ||
338 | with the environment in several ways. On invocation, the | |
339 | shell scans the environment and creates a _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br for each | |
340 | name found, giving it the corresponding value. Executed | |
341 | commands inherit the same environment. If the user modifies | |
342 | the values of these _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br_\bs or creates new ones, none of | |
343 | these affects the environment unless the e\bex\bxp\bpo\bor\brt\bt command is | |
344 | used to bind the shell's _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br to the environment. The | |
345 | environment seen by any executed command is thus composed of | |
346 | any unmodified name-value pairs originally inherited by the | |
347 | shell, plus any modifications or additions, all of which | |
348 | must be noted in e\bex\bxp\bpo\bor\brt\bt commands. | |
349 | ||
350 | The environment for any _\bs_\bi_\bm_\bp_\bl_\be-_\bc_\bo_\bm_\bm_\ba_\bn_\bd may be augmented by | |
351 | prefixing it with one or more assignments to _\bp_\ba_\br_\ba_\bm_\be_\bt_\be_\br_\bs. | |
352 | Thus these two lines are equivalent | |
353 | ||
354 | TERM=450 cmd args | |
355 | (export TERM; TERM=450; cmd args) | |
356 | ||
357 | If the -\b-k\bk flag is set, _\ba_\bl_\bl keyword arguments are placed in | |
358 | the environment, even if the occur after the command name. | |
359 | The following prints 'a=b c' and 'c': | |
360 | echo a=b c | |
361 | set -k | |
362 | echo a=b c | |
363 | ||
364 | S\bSi\big\bgn\bna\bal\bls\bs.\b. | |
365 | The INTERRUPT and QUIT signals for an invoked command are | |
366 | ignored if the command is followed by &\b&; otherwise signals | |
367 | have the values inherited by the shell from its parent. | |
368 | (But see also t\btr\bra\bap\bp.\b.) | |
369 | ||
370 | E\bEx\bxe\bec\bcu\but\bti\bio\bon\bn.\b. | |
371 | Each time a command is executed the above substitutions are | |
372 | carried out. Except for the 'special commands' listed below | |
373 | a new process is created and an attempt is made to execute | |
374 | the command via an _\be_\bx_\be_\bc_\bv_\be(2). | |
375 | ||
376 | The shell parameter $\b$P\bPA\bAT\bTH\bH defines the search path for the | |
377 | directory containing the command. Each alternative direc- | |
378 | tory name is separated by a colon (:\b:). The default path is | |
379 | :\b:/\b/b\bbi\bin\bn:\b:/\b/u\bus\bsr\br/\b/b\bbi\bin\bn. If the command name contains a /, the | |
380 | search path is not used. Otherwise, each directory in the | |
381 | path is searched for an executable file. If the file has | |
382 | execute permission but is not an _\ba._\bo_\bu_\bt file, it is assumed | |
383 | to be a file containing shell commands. A subshell (i.e., a | |
384 | separate process) is spawned to read it. A parenthesized | |
385 | command is also executed in a subshell. | |
386 | ||
387 | S\bSp\bpe\bec\bci\bia\bal\bl c\bco\bom\bmm\bma\ban\bnd\bds\bs.\b. | |
388 | The following commands are executed in the shell process and | |
389 | except where specified no input output redirection is | |
390 | ||
391 | ||
392 | ||
393 | Printed 7/9/88 May 5, 1986 6 | |
394 | ||
395 | ||
396 | ||
397 | ||
398 | ||
399 | ||
400 | SH(1) UNIX Programmer's Manual SH(1) | |
401 | ||
402 | ||
403 | ||
404 | permitted for such commands. | |
405 | ||
406 | #\b# For non-interactive shells, everything following the #\b# | |
407 | is treated as a comment, i.e. the rest of the line is | |
408 | ignored. For interactive shells, the #\b# has no special | |
409 | effect. | |
410 | ||
411 | :\b: No effect; the command does nothing. | |
412 | .\b. _\bf_\bi_\bl_\be | |
413 | Read and execute commands from _\bf_\bi_\bl_\be and return. The | |
414 | search path $\b$P\bPA\bAT\bTH\bH is used to find the directory con- | |
415 | taining _\bf_\bi_\bl_\be. | |
416 | b\bbr\bre\bea\bak\bk [_\bn] | |
417 | Exit from the enclosing f\bfo\bor\br or w\bwh\bhi\bil\ble\be loop, if any. If | |
418 | _\bn is specified, break _\bn levels. | |
419 | c\bco\bon\bnt\bti\bin\bnu\bue\be [_\bn] | |
420 | Resume the next iteration of the enclosing f\bfo\bor\br or w\bwh\bhi\bil\ble\be | |
421 | loop. If _\bn is specified, resume at the _\bn-th enclosing | |
422 | loop. | |
423 | c\bcd\bd [_\ba_\br_\bg] | |
424 | Change the current directory to _\ba_\br_\bg. The shell parame- | |
425 | ter $\b$H\bHO\bOM\bME\bE is the default _\ba_\br_\bg. | |
426 | e\bev\bva\bal\bl [_\ba_\br_\bg ...] | |
427 | The arguments are read as input to the shell and the | |
428 | resulting command(s) executed. | |
429 | e\bex\bxe\bec\bc [_\ba_\br_\bg ...] | |
430 | The command specified by the arguments is executed in | |
431 | place of this shell without creating a new process. | |
432 | Input output arguments may appear and if no other argu- | |
433 | ments are given cause the shell input output to be | |
434 | modified. | |
435 | e\bex\bxi\bit\bt [_\bn] | |
436 | Causes a non interactive shell to exit with the exit | |
437 | status specified by _\bn. If _\bn is omitted, the exit status | |
438 | is that of the last command executed. (An end of file | |
439 | will also exit from the shell.) | |
440 | e\bex\bxp\bpo\bor\brt\bt [_\bn_\ba_\bm_\be ...] | |
441 | The given names are marked for automatic export to the | |
442 | _\be_\bn_\bv_\bi_\br_\bo_\bn_\bm_\be_\bn_\bt of subsequently-executed commands. If no | |
443 | arguments are given, a list of exportable names is | |
444 | printed. | |
445 | l\blo\bog\bgi\bin\bn [_\ba_\br_\bg ...] | |
446 | Equivalent to 'exec login arg ...'. | |
447 | r\bre\bea\bad\bd _\bn_\ba_\bm_\be ... | |
448 | One line is read from the standard input; successive | |
449 | words of the input are assigned to the variables _\bn_\ba_\bm_\be | |
450 | in order, with leftover words to the last variable. | |
451 | The return code is 0 unless the end-of-file is encoun- | |
452 | tered. | |
453 | r\bre\bea\bad\bdo\bon\bnl\bly\by [_\bn_\ba_\bm_\be ...] | |
454 | The given names are marked readonly and the values of | |
455 | the these names may not be changed by subsequent | |
456 | ||
457 | ||
458 | ||
459 | Printed 7/9/88 May 5, 1986 7 | |
460 | ||
461 | ||
462 | ||
463 | ||
464 | ||
465 | ||
466 | SH(1) UNIX Programmer's Manual SH(1) | |
467 | ||
468 | ||
469 | ||
470 | assignment. If no arguments are given, a list of all | |
471 | readonly names is printed. | |
472 | s\bse\bet\bt [-\b-e\bek\bkn\bnp\bpt\btu\buv\bvx\bx [_\ba_\br_\bg ...]] | |
473 | -\b-e\be If non interactive, exit immediately if a command | |
474 | fails. | |
475 | -\b-k\bk All keyword arguments are placed in the environment | |
476 | for a command, not just those that precede the com- | |
477 | mand name. | |
478 | -\b-n\bn Read commands but do not execute them. | |
479 | -\b-t\bt Exit after reading and executing one command. | |
480 | -\b-u\bu Treat unset variables as an error when substituting. | |
481 | -\b-v\bv Print shell input lines as they are read. | |
482 | -\b-x\bx Print commands and their arguments as they are exe- | |
483 | cuted. | |
484 | -\b- Turn off the -\b-x\bx and -\b-v\bv options. | |
485 | ||
486 | These flags can also be used upon invocation of the | |
487 | shell. The current set of flags may be found in $\b$-\b-. | |
488 | ||
489 | Remaining arguments are positional parameters and are | |
490 | assigned, in order, to $\b$1\b1, $\b$2\b2, etc. If no arguments | |
491 | are given, the values of all names are printed. | |
492 | ||
493 | s\bsh\bhi\bif\bft\bt | |
494 | The positional parameters from $\b$2\b2... are renamed $\b$1\b1... | |
495 | ||
496 | t\bti\bim\bme\bes\bs | |
497 | Print the accumulated user and system times for | |
498 | processes run from the shell. | |
499 | ||
500 | t\btr\bra\bap\bp [_\ba_\br_\bg] [_\bn] ... | |
501 | _\bA_\br_\bg is a command to be read and executed when the shell | |
502 | receives signal(s) _\bn. (Note that _\ba_\br_\bg is scanned once | |
503 | when the trap is set and once when the trap is taken.) | |
504 | Trap commands are executed in order of signal number. | |
505 | If _\ba_\br_\bg is absent, all trap(s) _\bn are reset to their ori- | |
506 | ginal values. If _\ba_\br_\bg is the null string, this signal | |
507 | is ignored by the shell and by invoked commands. If _\bn | |
508 | is 0, the command _\ba_\br_\bg is executed on exit from the | |
509 | shell, otherwise upon receipt of signal _\bn as numbered | |
510 | in _\bs_\bi_\bg_\bv_\be_\bc(2). _\bT_\br_\ba_\bp with no arguments prints a list of | |
511 | commands associated with each signal number. | |
512 | ||
513 | u\bum\bma\bas\bsk\bk [ _\bn_\bn_\bn ] | |
514 | The user file creation mask is set to the octal value | |
515 | _\bn_\bn_\bn (see _\bu_\bm_\ba_\bs_\bk(2)). If _\bn_\bn_\bn is omitted, the current | |
516 | value of the mask is printed. | |
517 | ||
518 | w\bwa\bai\bit\bt [_\bn] | |
519 | Wait for the specified process and report its termina- | |
520 | tion status. If _\bn is not given, all currently active | |
521 | child processes are waited for. The return code from | |
522 | ||
523 | ||
524 | ||
525 | Printed 7/9/88 May 5, 1986 8 | |
526 | ||
527 | ||
528 | ||
529 | ||
530 | ||
531 | ||
532 | SH(1) UNIX Programmer's Manual SH(1) | |
533 | ||
534 | ||
535 | ||
536 | this command is that of the process waited for. | |
537 | ||
538 | I\bIn\bnv\bvo\boc\bca\bat\bti\bio\bon\bn.\b. | |
539 | If the first character of argument zero is -\b-, commands are | |
540 | read from $\b$H\bHO\bOM\bME\bE/\b/.\b.p\bpr\bro\bof\bfi\bil\ble\be, if such a file exists. Commands | |
541 | are then read as described below. The following flags are | |
542 | interpreted by the shell when it is invoked. | |
543 | -\b-c\bc _\bs_\bt_\br_\bi_\bn_\bg If the -\b-c\bc flag is present, commands are read from | |
544 | _\bs_\bt_\br_\bi_\bn_\bg. | |
545 | -\b-s\bs If the -\b-s\bs flag is present or if no arguments | |
546 | remain then commands are read from the standard | |
547 | input. Shell output is written to file descrip- | |
548 | tor 2. | |
549 | -\b-i\bi If the -\b-i\bi flag is present or if the shell input | |
550 | and output are attached to a terminal (as told by | |
551 | _\bg_\bt_\bt_\by) then this shell is _\bi_\bn_\bt_\be_\br_\ba_\bc_\bt_\bi_\bv_\be. In this | |
552 | case the terminate signal SIGTERM (see _\bs_\bi_\bg_\bv_\be_\bc(2)) | |
553 | is ignored (so that 'kill 0' does not kill an | |
554 | interactive shell) and the interrupt signal SIG- | |
555 | INT is caught and ignored (so that w\bwa\bai\bit\bt is inter- | |
556 | ruptible). In all cases SIGQUIT is ignored by | |
557 | the shell. | |
558 | ||
559 | The remaining flags and arguments are described under the | |
560 | s\bse\bet\bt command. | |
561 | ||
562 | F\bFI\bIL\bLE\bES\bS | |
563 | $HOME/.\b.profile | |
564 | /tmp/sh* | |
565 | /dev/null | |
566 | ||
567 | S\bSE\bEE\bE A\bAL\bLS\bSO\bO | |
568 | csh(1), test(1), execve(2), environ(7) | |
569 | ||
570 | D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS | |
571 | Errors detected by the shell, such as syntax errors cause | |
572 | the shell to return a non zero exit status. If the shell is | |
573 | being used non interactively then execution of the shell | |
574 | file is abandoned. Otherwise, the shell returns the exit | |
575 | status of the last command executed (see also e\bex\bxi\bit\bt). | |
576 | ||
577 | B\bBU\bUG\bGS\bS | |
578 | If << is used to provide standard input to an asynchronous | |
579 | process invoked by &, the shell gets mixed up about naming | |
580 | the input document. A garbage file /tmp/sh* is created, and | |
581 | the shell complains about not being able to find the file by | |
582 | another name. | |
583 | ||
584 | ||
585 | ||
586 | ||
587 | ||
588 | ||
589 | ||
590 | ||
591 | Printed 7/9/88 May 5, 1986 9 | |
592 | ||
593 | ||
594 |