Commit | Line | Data |
---|---|---|
32424d04 C |
1 | CSH(1) BSD Reference Manual CSH(1) |
2 | ||
3 | N\bNA\bAM\bME\bE | |
4 | c\bcs\bsh\bh - a shell (command interpreter) with C-like syntax | |
5 | ||
6 | S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS | |
7 | c\bcs\bsh\bh [-\b-b\bbc\bce\bef\bfi\bin\bns\bst\btv\bvV\bVx\bxX\bX] [arg ...] | |
8 | c\bcs\bsh\bh [-\b-l\bl] | |
9 | ||
10 | D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN | |
11 | The c\bcs\bsh\bh is a command language interpreter incorporating a history mecha- | |
12 | nism (see H\bHi\bis\bst\bto\bor\bry\by S\bSu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bns\bs), job control facilities (see J\bJo\bob\bbs\bs), in- | |
13 | teractive file name and user name completion (see F\bFi\bil\ble\be N\bNa\bam\bme\be C\bCo\bom\bmp\bpl\ble\bet\bti\bio\bon\bn), | |
14 | and a C-like syntax. It is used both as an interactive login shell and a | |
15 | shell script command processor. | |
16 | ||
17 | A\bAr\brg\bgu\bum\bme\ben\bnt\bt l\bli\bis\bst\bt p\bpr\bro\boc\bce\bes\bss\bsi\bin\bng\bg | |
18 | If the first argument (argument 0) to the shell is `-\b-', then this is a | |
19 | login shell. A login shell also can be specified by invoking the shell | |
20 | with the `-\b-l\bl' flag as the only argument. | |
21 | ||
22 | The rest of the flag arguments are interpreted as follows: | |
23 | ||
24 | -\b-b\bb This flag forces a ``break'' from option processing, causing any | |
25 | further shell arguments to be treated as non-option arguments. | |
26 | The remaining arguments will not be interpreted as shell options. | |
27 | This may be used to pass options to a shell script without confu- | |
28 | sion or possible subterfuge. The shell will not run a set-user ID | |
29 | script without this option. | |
30 | ||
31 | -\b-c\bc Commands are read from the (single) following argument which must | |
32 | be present. Any remaining arguments are placed in _\ba_\br_\bg_\bv. | |
33 | ||
34 | -\b-e\be The shell exits if any invoked command terminates abnormally or | |
35 | yields a non-zero exit status. | |
36 | ||
37 | -\b-f\bf The shell will start faster, because it will neither search for | |
38 | nor execute commands from the file _\b._\bc_\bs_\bh_\br_\bc in the invoker's home | |
39 | directory. | |
40 | ||
41 | -\b-i\bi The shell is interactive and prompts for its top-level input, even | |
42 | if it appears not to be a terminal. Shells are interactive with- | |
43 | out this option if their inputs and outputs are terminals. | |
44 | ||
45 | -\b-l\bl The shell is a login shell (only applicable if -\b-l\bl is the only flag | |
46 | specified). | |
47 | ||
48 | -\b-n\bn Commands are parsed, but not executed. This aids in syntactic | |
49 | checking of shell scripts. | |
50 | ||
51 | -\b-s\bs Command input is taken from the standard input. | |
52 | ||
53 | -\b-t\bt A single line of input is read and executed. A `\' may be used to | |
54 | escape the newline at the end of this line and continue onto an- | |
55 | other line. | |
56 | ||
57 | -\b-v\bv Causes the _\bv_\be_\br_\bb_\bo_\bs_\be variable to be set, with the effect that com- | |
58 | mand input is echoed after history substitution. | |
59 | ||
60 | -\b-x\bx Causes the _\be_\bc_\bh_\bo variable to be set, so that commands are echoed | |
61 | immediately before execution. | |
62 | ||
63 | -\b-V\bV Causes the _\bv_\be_\br_\bb_\bo_\bs_\be variable to be set even before _\b._\bc_\bs_\bh_\br_\bc is exe- | |
64 | ||
65 | ||
66 | cuted. | |
67 | ||
68 | -\b-X\bX Is to -\b-x\bx as -\b-V\bV is to -\b-v\bv. | |
69 | ||
70 | After processing of flag arguments, if arguments remain but none of the | |
71 | -\b-c\bc, -\b-i\bi, -\b-s\bs, or -\b-t\bt options were given, the first argument is taken as the | |
72 | name of a file of commands to be executed. The shell opens this file, | |
73 | and saves its name for possible resubstitution by `$0'. Since many sys- | |
74 | tems use either the standard version 6 or version 7 shells whose shell | |
75 | scripts are not compatible with this shell, the shell will execute such a | |
76 | `standard' shell if the first character of a script is not a `#', i.e., | |
77 | if the script does not start with a comment. Remaining arguments ini- | |
78 | tialize the variable _\ba_\br_\bg_\bv. | |
79 | ||
80 | An instance of c\bcs\bsh\bh begins by executing commands from the file | |
81 | _\b/_\be_\bt_\bc_\b/_\bc_\bs_\bh_\b._\bc_\bs_\bh_\br_\bc and, if this is a login shell, _\b/_\be_\bt_\bc_\b/_\bc_\bs_\bh_\b._\bl_\bo_\bg_\bi_\bn. It then ex- | |
82 | ecutes commands from _\b._\bc_\bs_\bh_\br_\bc in the _\bh_\bo_\bm_\be directory of the invoker, and, if | |
83 | this is a login shell, the file _\b._\bl_\bo_\bg_\bi_\bn in the same location. It is typi- | |
84 | cal for users on crt's to put the command ``stty crt'' in their _\b._\bl_\bo_\bg_\bi_\bn | |
85 | file, and to also invoke tset(1) there. | |
86 | ||
87 | In the normal case, the shell will begin reading commands from the termi- | |
88 | nal, prompting with `% '. Processing of arguments and the use of the | |
89 | shell to process files containing command scripts will be described lat- | |
90 | er. | |
91 | ||
92 | The shell repeatedly performs the following actions: a line of command | |
93 | input is read and broken into _\bw_\bo_\br_\bd_\bs. This sequence of words is placed on | |
94 | the command history list and parsed. Finally each command in the current | |
95 | line is executed. | |
96 | ||
97 | When a login shell terminates it executes commands from the files _\b._\bl_\bo_\bg_\bo_\bu_\bt | |
98 | in the user's _\bh_\bo_\bm_\be directory and _\b/_\be_\bt_\bc_\b/_\bc_\bs_\bh_\b._\bl_\bo_\bg_\bo_\bu_\bt. | |
99 | ||
100 | L\bLe\bex\bxi\bic\bca\bal\bl s\bst\btr\bru\buc\bct\btu\bur\bre\be | |
101 | The shell splits input lines into words at blanks and tabs with the fol- | |
102 | lowing exceptions. The characters `&' `|' `;' `<' `>' `(' `)' form sepa- | |
103 | rate words. If doubled in `&&', `||', `<<' or `>>' these pairs form sin- | |
104 | gle words. These parser metacharacters may be made part of other words, | |
105 | or prevented their special meaning, by preceding them with `\'. A new- | |
106 | line preceded by a `\' is equivalent to a blank. | |
107 | ||
108 | Strings enclosed in matched pairs of quotations, `'', ``' or `"', form | |
109 | parts of a word; metacharacters in these strings, including blanks and | |
110 | tabs, do not form separate words. These quotations have semantics to be | |
111 | described later. Within pairs of `'' or `"' characters, a newline pre- | |
112 | ceded by a `\' gives a true newline character. | |
113 | ||
114 | When the shell's input is not a terminal, the character `#' introduces a | |
115 | comment that continues to the end of the input line. It is prevented | |
116 | this special meaning when preceded by `\' and in quotations using ``', | |
117 | `'', and `"'. | |
118 | ||
119 | C\bCo\bom\bmm\bma\ban\bnd\bds\bs | |
120 | A simple command is a sequence of words, the first of which specifies the | |
121 | command to be executed. A simple command or a sequence of simple com- | |
122 | mands separated by `|' characters forms a pipeline. The output of each | |
123 | command in a pipeline is connected to the input of the next. Sequences | |
124 | of pipelines may be separated by `;', and are then executed sequentially. | |
125 | A sequence of pipelines may be executed without immediately waiting for | |
126 | it to terminate by following it with an `&'. | |
127 | ||
128 | Any of the above may be placed in `(' `)' to form a simple command (that | |
129 | may be a component of a pipeline, etc.). It is also possible to separate | |
130 | pipelines with `||' or `&&' showing, as in the C language, that the sec- | |
131 | ond is to be executed only if the first fails or succeeds respectively. | |
132 | (See _\bE_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn_\bs.) | |
133 | ||
134 | J\bJo\bob\bbs\bs | |
135 | The shell associates a _\bj_\bo_\bb with each pipeline. It keeps a table of cur- | |
136 | rent jobs, printed by the _\bj_\bo_\bb_\bs command, and assigns them small integer | |
137 | numbers. When a job is started asynchronously with `&', the shell prints | |
138 | a line that looks like: | |
139 | ||
140 | [1] 1234 | |
141 | ||
142 | showing that the job which was started asynchronously was job number 1 | |
143 | and had one (top-level) process, whose process id was 1234. | |
144 | ||
145 | If you are running a job and wish to do something else you may hit the | |
146 | key ^\b^Z\bZ (control-Z) which sends a STOP signal to the current job. The | |
147 | shell will then normally show that the job has been `Stopped', and print | |
148 | another prompt. You can then manipulate the state of this job, putting | |
149 | it in the _\bb_\ba_\bc_\bk_\bg_\br_\bo_\bu_\bn_\bd with the _\bb_\bg command, or run some other commands and | |
150 | eventually bring the job back into the foreground with the _\bf_\bo_\br_\be_\bg_\br_\bo_\bu_\bn_\bd | |
151 | command _\bf_\bg. A ^\b^Z\bZ takes effect immediately and is like an interrupt in | |
152 | that pending output and unread input are discarded when it is typed. | |
153 | There is another special key ^\b^Y\bY that does not generate a STOP signal un- | |
154 | til a program attempts to read(2) it. This request can usefully be typed | |
155 | ahead when you have prepared some commands for a job that you wish to | |
156 | stop after it has read them. | |
157 | ||
158 | A job being run in the background will stop if it tries to read from the | |
159 | terminal. Background jobs are normally allowed to produce output, but | |
160 | this can be disabled by giving the command ``stty tostop''. If you set | |
161 | this tty option, then background jobs will stop when they try to produce | |
162 | output like they do when they try to read input. | |
163 | ||
164 | There are several ways to refer to jobs in the shell. The character `%' | |
165 | introduces a job name. If you wish to refer to job number 1, you can | |
166 | name it as `%1'. Just naming a job brings it to the foreground; thus | |
167 | `%1' is a synonym for `fg %1', bringing job number 1 back into the fore- | |
168 | ground. Similarly saying `%1 &' resumes job number 1 in the background. | |
169 | Jobs can also be named by prefixes of the string typed in to start them, | |
170 | if these prefixes are unambiguous, thus `%ex' would normally restart a | |
171 | suspended ex(1) job, if there were only one suspended job whose name be- | |
172 | gan with the string `ex'. It is also possible to say `%?string' which | |
173 | specifies a job whose text contains _\bs_\bt_\br_\bi_\bn_\bg, if there is only one such | |
174 | job. | |
175 | ||
176 | The shell maintains a notion of the current and previous jobs. In output | |
177 | about jobs, the current job is marked with a `+' and the previous job | |
178 | with a `-'. The abbreviation `%+' refers to the current job and `%-' | |
179 | refers to the previous job. For close analogy with the syntax of the | |
180 | _\bh_\bi_\bs_\bt_\bo_\br_\by mechanism (described below), `%%' is also a synonym for the cur- | |
181 | rent job. | |
182 | ||
183 | The job control mechanism requires that the stty(1) option n\bne\bew\bw be set. It | |
184 | is an artifact from a _\bn_\be_\bw implementation of the tty driver that allows | |
185 | generation of interrupt characters from the keyboard to tell jobs to | |
186 | stop. See stty(1) for details on setting options in the new tty driver. | |
187 | ||
188 | S\bSt\bta\bat\btu\bus\bs r\bre\bep\bpo\bor\brt\bti\bin\bng\bg | |
189 | This shell learns immediately whenever a process changes state. It nor- | |
190 | mally informs you whenever a job becomes blocked so that no further | |
191 | progress is possible, but only just before it prints a prompt. This is | |
192 | done so that it does not otherwise disturb your work. If, however, you | |
193 | set the shell variable _\bn_\bo_\bt_\bi_\bf_\by, the shell will notify you immediately of | |
194 | changes of status in background jobs. There is also a shell command | |
195 | _\bn_\bo_\bt_\bi_\bf_\by that marks a single process so that its status changes will be im- | |
196 | mediately reported. By default _\bn_\bo_\bt_\bi_\bf_\by marks the current process; simply | |
197 | say `notify' after starting a background job to mark it. | |
198 | ||
199 | When you try to leave the shell while jobs are stopped, you will be | |
200 | warned that `You have stopped jobs.' You may use the _\bj_\bo_\bb_\bs command to see | |
201 | what they are. If you do this or immediately try to exit again, the | |
202 | shell will not warn you a second time, and the suspended jobs will be | |
203 | terminated. | |
204 | ||
205 | F\bFi\bil\ble\be N\bNa\bam\bme\be C\bCo\bom\bmp\bpl\ble\bet\bti\bio\bon\bn | |
206 | When the file name completion feature is enabled by setting the shell | |
207 | variable _\bf_\bi_\bl_\be_\bc (see s\bse\bet\bt), c\bcs\bsh\bh will interactively complete file names and | |
208 | user names from unique prefixes, when they are input from the terminal | |
209 | followed by the escape character (the escape key, or control-[) For exam- | |
210 | ple, if the current directory looks like | |
211 | ||
212 | DSC.OLD bin cmd lib xmpl.c | |
213 | DSC.NEW chaosnet cmtest mail xmpl.o | |
214 | bench class dev mbox xmpl.out | |
215 | ||
216 | and the input is | |
217 | ||
218 | % vi ch<escape> | |
219 | ||
220 | c\bcs\bsh\bh will complete the prefix ``ch'' to the only matching file name | |
221 | ``chaosnet'', changing the input line to | |
222 | ||
223 | % vi chaosnet | |
224 | ||
225 | However, given | |
226 | ||
227 | % vi D<escape> | |
228 | ||
229 | c\bcs\bsh\bh will only expand the input to | |
230 | ||
231 | % vi DSC. | |
232 | ||
233 | and will sound the terminal bell to indicate that the expansion is incom- | |
234 | plete, since there are two file names matching the prefix ``D''. | |
235 | ||
236 | If a partial file name is followed by the end-of-file character (usually | |
237 | control-D), then, instead of completing the name, c\bcs\bsh\bh will list all file | |
238 | names matching the prefix. For example, the input | |
239 | ||
240 | % vi D<control-D> | |
241 | ||
242 | causes all files beginning with ``D'' to be listed: | |
243 | ||
244 | DSC.NEW DSC.OLD | |
245 | ||
246 | while the input line remains unchanged. | |
247 | ||
248 | The same system of escape and end-of-file can also be used to expand par- | |
249 | tial user names, if the word to be completed (or listed) begins with the | |
250 | character ``~''. For example, typing | |
251 | ||
252 | cd ~ro<escape> | |
253 | ||
254 | may produce the expansion | |
255 | ||
256 | cd ~root | |
257 | ||
258 | The use of the terminal bell to signal errors or multiple matches can be | |
259 | inhibited by setting the variable _\bn_\bo_\bb_\be_\be_\bp. | |
260 | ||
261 | Normally, all files in the particular directory are candidates for name | |
262 | completion. Files with certain suffixes can be excluded from considera- | |
263 | tion by setting the variable _\bf_\bi_\bg_\bn_\bo_\br_\be to the list of suffixes to be ig- | |
264 | nored. Thus, if _\bf_\bi_\bg_\bn_\bo_\br_\be is set by the command | |
265 | ||
266 | % set fignore = (.o .out) | |
267 | ||
268 | then typing | |
269 | ||
270 | % vi x<escape> | |
271 | ||
272 | would result in the completion to | |
273 | ||
274 | % vi xmpl.c | |
275 | ||
276 | ignoring the files "xmpl.o" and "xmpl.out". However, if the only comple- | |
277 | tion possible requires not ignoring these suffixes, then they are not ig- | |
278 | nored. In addition, _\bf_\bi_\bg_\bn_\bo_\br_\be does not affect the listing of file names by | |
279 | control-D. All files are listed regardless of their suffixes. | |
280 | ||
281 | S\bSu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bns\bs | |
282 | We now describe the various transformations the shell performs on the in- | |
283 | put in the order in which they occur. | |
284 | ||
285 | H\bHi\bis\bst\bto\bor\bry\by s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bns\bs | |
286 | History substitutions place words from previous command input as portions | |
287 | of new commands, making it easy to repeat commands, repeat arguments of a | |
288 | previous command in the current command, or fix spelling mistakes in the | |
289 | previous command with little typing and a high degree of confidence. | |
290 | History substitutions begin with the character `!' and may begin _\ba_\bn_\by_\bw_\bh_\be_\br_\be | |
291 | in the input stream (with the proviso that they d\bdo\bo n\bno\bot\bt nest.) This `!' | |
292 | may be preceded by a `\' to prevent its special meaning; for convenience, | |
293 | an `!' is passed unchanged when it is followed by a blank, tab, newline, | |
294 | `=' or `('. (History substitutions also occur when an input line begins | |
295 | with `^'. This special abbreviation will be described later.) Any input | |
296 | line that contains history substitution is echoed on the terminal before | |
297 | it is executed as it could have been typed without history substitution. | |
298 | ||
299 | Commands input from the terminal that consist of one or more words are | |
300 | saved on the history list. The history substitutions reintroduce se- | |
301 | quences of words from these saved commands into the input stream. The | |
302 | size of the history list is controlled by the _\bh_\bi_\bs_\bt_\bo_\br_\by variable; the pre- | |
303 | vious command is always retained, regardless of the value of the history | |
304 | variable. Commands are numbered sequentially from 1. | |
305 | ||
306 | For definiteness, consider the following output from the _\bh_\bi_\bs_\bt_\bo_\br_\by command: | |
307 | ||
308 | 9 write michael | |
309 | 10 ex write.c | |
310 | 11 cat oldwrite.c | |
311 | 12 diff *write.c | |
312 | ||
313 | The commands are shown with their event numbers. It is not usually nec- | |
314 | essary to use event numbers, but the current event number can be made | |
315 | part of the _\bp_\br_\bo_\bm_\bp_\bt by placing an `!' in the prompt string. | |
316 | ||
317 | With the current event 13 we can refer to previous events by event number | |
318 | `!11', relatively as in `!-2' (referring to the same event), by a prefix | |
319 | of a command word as in `!d' for event 12 or `!wri' for event 9, or by a | |
320 | string contained in a word in the command as in `!?mic?' also referring | |
321 | to event 9. These forms, without further change, simply reintroduce the | |
322 | words of the specified events, each separated by a single blank. As a | |
323 | special case, `!!' refers to the previous command; thus `!!' alone is a | |
324 | _\br_\be_\bd_\bo. | |
325 | ||
326 | To select words from an event we can follow the event specification by a | |
327 | `:' and a designator for the desired words. The words of an input line | |
328 | are numbered from 0, the first (usually command) word being 0, the second | |
329 | word (first argument) being 1, etc. The basic word designators are: | |
330 | ||
331 | 0 first (command) word | |
332 | _\bn _\bn'th argument | |
333 | ^ first argument, i.e., `1' | |
334 | $ last argument | |
335 | % word matched by (immediately preceding) ?_\bs? search | |
336 | _\bx_\b-_\by range of words | |
337 | _\b-_\by abbreviates _\b`_\b0_\b-_\by_\b' | |
338 | * abbreviates `^-$', or nothing if only 1 word in event | |
339 | _\bx_\b* abbreviates _\b`_\bx_\b-_\b$_\b' | |
340 | _\bx_\b- like _\b`_\bx_\b*_\b' but omitting word `$' | |
341 | ||
342 | The `:' separating the event specification from the word designator can | |
343 | be omitted if the argument selector begins with a `^', `$', `*' `-' or | |
344 | `%'. After the optional word designator can be placed a sequence of mod- | |
345 | ifiers, each preceded by a `:'. The following modifiers are defined: | |
346 | ||
347 | h Remove a trailing pathname component, leaving the head. | |
348 | r Remove a trailing `.xxx' component, leaving the root name. | |
349 | e Remove all but the extension `.xxx' part. | |
350 | s_\b/_\bl_\b/_\br_\b/ Substitute _\bl for _\br | |
351 | t Remove all leading pathname components, leaving the tail. | |
352 | & Repeat the previous substitution. | |
353 | g Apply the change once on each word, prefixing the above, | |
354 | e.g., `g&'. | |
355 | a Apply the change as many times as possible on a single | |
356 | word, prefixing the above. It can be used together with `g' | |
357 | to apply a substitution globally. | |
358 | p Print the new command line but do not execute it. | |
359 | q Quote the substituted words, preventing further substitu- | |
360 | tions. | |
361 | x Like q, but break into words at blanks, tabs and newlines. | |
362 | ||
363 | Unless preceded by a `g' the change is applied only to the first modifi- | |
364 | able word. With substitutions, it is an error for no word to be applica- | |
365 | ble. | |
366 | ||
367 | The left hand side of substitutions are not regular expressions in the | |
368 | sense of the editors, but instead strings. Any character may be used as | |
369 | the delimiter in place of `/'; a `\' quotes the delimiter into the _\bl and | |
370 | _\br strings. The character `&' in the right hand side is replaced by the | |
371 | text from the left. A `\' also quotes `&'. A null _\bl (`//') uses the | |
372 | previous string either from an _\bl or from a contextual scan string _\bs in | |
373 | `!?_\bs\?'. The trailing delimiter in the substitution may be omitted if a | |
374 | newline follows immediately as may the trailing `?' in a contextual scan. | |
375 | ||
376 | A history reference may be given without an event specification, e.g., | |
377 | `!$'. Here, the reference is to the previous command unless a previous | |
378 | history reference occurred on the same line in which case this form re- | |
379 | peats the previous reference. Thus `!?foo?^ !$' gives the first and last | |
380 | arguments from the command matching `?foo?'. | |
381 | ||
382 | A special abbreviation of a history reference occurs when the first non- | |
383 | blank character of an input line is a `^'. This is equivalent to `!:s^' | |
384 | providing a convenient shorthand for substitutions on the text of the | |
385 | previous line. Thus `^lb^lib' fixes the spelling of `lib' in the previ- | |
386 | ous command. Finally, a history substitution may be surrounded with `{' | |
387 | and `}' if necessary to insulate it from the characters that follow. | |
388 | Thus, after `ls -ld ~paul' we might do `!{l}a' to do `ls -ld ~paula', | |
389 | while `!la' would look for a command starting with `la'. | |
390 | ||
391 | Q\bQu\buo\bot\bta\bat\bti\bio\bon\bns\bs w\bwi\bit\bth\bh '\b' a\ban\bnd\bd "\b" | |
392 | The quotation of strings by `'' and `"' can be used to prevent all or | |
393 | some of the remaining substitutions. Strings enclosed in `'' are pre- | |
394 | vented any further interpretation. Strings enclosed in `"' may be ex- | |
395 | panded as described below. | |
396 | ||
397 | In both cases the resulting text becomes (all or part of) a single word; | |
398 | only in one special case (see _\bC_\bo_\bm_\bm_\ba_\bn_\bd _\bS_\bu_\bb_\bs_\bt_\bi_\bt_\bu_\bt_\bi_\bo_\bn below) does a `"' | |
399 | quoted string yield parts of more than one word; `'' quoted strings never | |
400 | do. | |
401 | ||
402 | A\bAl\bli\bia\bas\bs s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn | |
403 | The shell maintains a list of aliases that can be established, displayed | |
404 | and modified by the _\ba_\bl_\bi_\ba_\bs and _\bu_\bn_\ba_\bl_\bi_\ba_\bs commands. After a command line is | |
405 | scanned, it is parsed into distinct commands and the first word of each | |
406 | command, left-to-right, is checked to see if it has an alias. If it | |
407 | does, then the text that is the alias for that command is reread with the | |
408 | history mechanism available as though that command were the previous in- | |
409 | put line. The resulting words replace the command and argument list. If | |
410 | no reference is made to the history list, then the argument list is left | |
411 | unchanged. | |
412 | ||
413 | Thus if the alias for `ls' is `ls -l' the command `ls /usr' would map to | |
414 | `ls -l /usr', the argument list here being undisturbed. Similarly if the | |
415 | alias for `lookup' was `grep !^ /etc/passwd' then `lookup bill' would map | |
416 | to `grep bill /etc/passwd'. | |
417 | ||
418 | If an alias is found, the word transformation of the input text is per- | |
419 | formed and the aliasing process begins again on the reformed input line. | |
420 | Looping is prevented if the first word of the new text is the same as the | |
421 | old by flagging it to prevent further aliasing. Other loops are detected | |
422 | and cause an error. | |
423 | ||
424 | Note that the mechanism allows aliases to introduce parser metasyntax. | |
425 | Thus, we can `alias print 'pr \!* | lpr'' to make a command that _\bp_\br's its | |
426 | arguments to the line printer. | |
427 | ||
428 | V\bVa\bar\bri\bia\bab\bbl\ble\be s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn | |
429 | The shell maintains a set of variables, each of which has as value a list | |
430 | of zero or more words. Some of these variables are set by the shell or | |
431 | referred to by it. For instance, the _\ba_\br_\bg_\bv variable is an image of the | |
432 | shell's argument list, and words of this variable's value are referred to | |
433 | in special ways. | |
434 | ||
435 | The values of variables may be displayed and changed by using the _\bs_\be_\bt and | |
436 | _\bu_\bn_\bs_\be_\bt commands. Of the variables referred to by the shell a number are | |
437 | toggles; the shell does not care what their value is, only whether they | |
438 | are set or not. For instance, the _\bv_\be_\br_\bb_\bo_\bs_\be variable is a toggle that | |
439 | causes command input to be echoed. The setting of this variable results | |
440 | from the -\b-v\bv command line option. | |
441 | ||
442 | Other operations treat variables numerically. The `@' command permits | |
443 | numeric calculations to be performed and the result assigned to a vari- | |
444 | able. Variable values are, however, always represented as (zero or more) | |
445 | strings. For the purposes of numeric operations, the null string is con- | |
446 | sidered to be zero, and the second and additional words of multiword val- | |
447 | ues are ignored. | |
448 | ||
449 | After the input line is aliased and parsed, and before each command is | |
450 | executed, variable substitution is performed keyed by `$' characters. | |
451 | This expansion can be prevented by preceding the `$' with a `\' except | |
452 | within `"'s where it _\ba_\bl_\bw_\ba_\by_\bs occurs, and within `''s where it _\bn_\be_\bv_\be_\br oc- | |
453 | curs. Strings quoted by ``' are interpreted later (see C\bCo\bom\bmm\bma\ban\bnd\bd | |
454 | s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn below) so `$' substitution does not occur there until later, | |
455 | if at all. A `$' is passed unchanged if followed by a blank, tab, or | |
456 | end-of-line. | |
457 | ||
458 | Input/output redirections are recognized before variable expansion, and | |
459 | are variable expanded separately. Otherwise, the command name and entire | |
460 | argument list are expanded together. It is thus possible for the first | |
461 | (command) word (to this point) to generate more than one word, the first | |
462 | of which becomes the command name, and the rest of which become argu- | |
463 | ments. | |
464 | ||
465 | Unless enclosed in `"' or given the `:q' modifier the results of variable | |
466 | substitution may eventually be command and filename substituted. Within | |
467 | `"', a variable whose value consists of multiple words expands to a (por- | |
468 | tion of) a single word, with the words of the variables value separated | |
469 | by blanks. When the `:q' modifier is applied to a substitution the vari- | |
470 | able will expand to multiple words with each word separated by a blank | |
471 | and quoted to prevent later command or filename substitution. | |
472 | ||
473 | The following metasequences are provided for introducing variable values | |
474 | into the shell input. Except as noted, it is an error to reference a | |
475 | variable that is not set. | |
476 | ||
477 | $name | |
478 | ${name} | |
479 | Are replaced by the words of the value of variable _\bn_\ba_\bm_\be, | |
480 | each separated by a blank. Braces insulate _\bn_\ba_\bm_\be from fol- | |
481 | lowing characters that would otherwise be part of it. | |
482 | Shell variables have names consisting of up to 20 letters | |
483 | and digits starting with a letter. The underscore charac- | |
484 | ter is considered a letter. If _\bn_\ba_\bm_\be is not a shell vari- | |
485 | able, but is set in the environment, then that value is re- | |
486 | turned (but : modifiers and the other forms given below are | |
487 | not available here). | |
488 | $name[selector] | |
489 | ${name[selector] } | |
490 | May be used to select only some of the words from the value | |
491 | of _\bn_\ba_\bm_\be. The selector is subjected to `$' substitution and | |
492 | may consist of a single number or two numbers separated by | |
493 | a `-'. The first word of a variables value is numbered | |
494 | `1'. If the first number of a range is omitted it defaults | |
495 | to `1'. If the last number of a range is omitted it de- | |
496 | faults to `$#name'. The selector `*' selects all words. | |
497 | It is not an error for a range to be empty if the second | |
498 | argument is omitted or in range. | |
499 | $#name | |
500 | ${#name} | |
501 | Gives the number of words in the variable. This is useful | |
502 | for later use in a `$argv[selector]'. | |
503 | $0 Substitutes the name of the file from which command input | |
504 | is being read. An error occurs if the name is not known. | |
505 | $number | |
506 | ${number} | |
507 | Equivalent to `$argv[number]'. | |
508 | $* Equivalent to `$argv[*]'. The modifiers `:e', `:h', `:t', | |
509 | `:r', `:q' and `:x' may be applied to the substitutions | |
510 | above as may `:gh', `:gt' and `:gr'. If braces `{' '}' ap- | |
511 | pear in the command form then the modifiers must appear | |
512 | within the braces. The current implementation allows only | |
513 | one `:' modifier on each `$' expansion. | |
514 | ||
515 | The following substitutions may not be modified with `:' modifiers. | |
516 | $?name | |
517 | ${?name} | |
518 | Substitutes the string `1' if name is set, `0' if it is | |
519 | not. | |
520 | $?0 Substitutes `1' if the current input filename is known, `0' | |
521 | if it is not. | |
522 | $$ Substitute the (decimal) process number of the (parent) | |
523 | shell. | |
524 | $! Substitute the (decimal) process number of the last back- | |
525 | ground process started by this shell. | |
526 | $< Substitutes a line from the standard input, with no further | |
527 | interpretation. It can be used to read from the keyboard | |
528 | in a shell script. | |
529 | ||
530 | C\bCo\bom\bmm\bma\ban\bnd\bd a\ban\bnd\bd f\bfi\bil\ble\ben\bna\bam\bme\be s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn | |
531 | The remaining substitutions, command and filename substitution, are ap- | |
532 | plied selectively to the arguments of builtin commands. By selectively, | |
533 | we mean that portions of expressions which are not evaluated are not sub- | |
534 | jected to these expansions. For commands that are not internal to the | |
535 | shell, the command name is substituted separately from the argument list. | |
536 | This occurs very late, after input-output redirection is performed, and | |
537 | in a child of the main shell. | |
538 | ||
539 | C\bCo\bom\bmm\bma\ban\bnd\bd s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn | |
540 | Command substitution is shown by a command enclosed in ``'. The output | |
541 | from such a command is normally broken into separate words at blanks, | |
542 | tabs and newlines, with null words being discarded; this text then re- | |
543 | places the original string. Within `"'s, only newlines force new words; | |
544 | blanks and tabs are preserved. | |
545 | ||
546 | In any case, the single final newline does not force a new word. Note | |
547 | that it is thus possible for a command substitution to yield only part of | |
548 | a word, even if the command outputs a complete line. | |
549 | ||
550 | F\bFi\bil\ble\ben\bna\bam\bme\be s\bsu\bub\bbs\bst\bti\bit\btu\but\bti\bio\bon\bn | |
551 | If a word contains any of the characters `*', `?', `[' or `{' or begins | |
552 | with the character `~', then that word is a candidate for filename sub- | |
553 | stitution, also known as `globbing'. This word is then regarded as a | |
554 | pattern, and replaced with an alphabetically sorted list of file names | |
555 | that match the pattern. In a list of words specifying filename substitu- | |
556 | tion it is an error for no pattern to match an existing file name, but it | |
557 | is not required for each pattern to match. Only the metacharacters `*', | |
558 | `?' and `[' imply pattern matching, the characters `~' and `{' being more | |
559 | akin to abbreviations. | |
560 | ||
561 | In matching filenames, the character `.' at the beginning of a filename | |
562 | or immediately following a `/', as well as the character `/' must be | |
563 | matched explicitly. The character `*' matches any string of characters, | |
564 | including the null string. The character `?' matches any single charac- | |
565 | ter. The sequence `[...]' matches any one of the characters enclosed. | |
566 | Within `[...]', a pair of characters separated by `-' matches any charac- | |
567 | ter lexically between the two (inclusive). | |
568 | ||
569 | The character `~' at the beginning of a filename refers to home directo- | |
570 | ries. Standing alone, i.e., `~' it expands to the invokers home directo- | |
571 | ry as reflected in the value of the variable _\bh_\bo_\bm_\be. When followed by a | |
572 | name consisting of letters, digits and `-' characters, the shell searches | |
573 | for a user with that name and substitutes their home directory; thus | |
574 | `~ken' might expand to `/usr/ken' and `~ken/chmach' to `/usr/ken/chmach'. | |
575 | If the character `~' is followed by a character other than a letter or | |
576 | `/' or does not appear at the beginning of a word, it is left undis- | |
577 | turbed. | |
578 | ||
579 | The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'. Left to | |
580 | right order is preserved, with results of matches being sorted separately | |
581 | at a low level to preserve this order. This construct may be nested. | |
582 | Thus, `~source/s1/{oldls,ls}.c' expands to `/usr/source/s1/oldls.c | |
583 | /usr/source/s1/ls.c' without chance of error if the home directory for | |
584 | `source' is `/usr/source'. Similarly `../{memo,*box}' might expand to | |
585 | `../memo ../box ../mbox'. (Note that `memo' was not sorted with the re- | |
586 | sults of the match to `*box'.) As a special case `{', `}' and `{}' are | |
587 | passed undisturbed. | |
588 | ||
589 | I\bIn\bnp\bpu\but\bt/\b/o\bou\but\btp\bpu\but\bt | |
590 | The standard input and the standard output of a command may be redirected | |
591 | with the following syntax: | |
592 | ||
593 | ||
594 | ||
595 | < name Open file _\bn_\ba_\bm_\be (which is first variable, command and file- | |
596 | name expanded) as the standard input. | |
597 | << word | |
598 | Read the shell input up to a line that is identical to | |
599 | _\bw_\bo_\br_\bd. _\bW_\bo_\br_\bd is not subjected to variable, filename or com- | |
600 | mand substitution, and each input line is compared to _\bw_\bo_\br_\bd | |
601 | before any substitutions are done on the input line. Un- | |
602 | less a quoting `\', `"', `' or ``' appears in _\bw_\bo_\br_\bd, vari- | |
603 | able and command substitution is performed on the interven- | |
604 | ing lines, allowing `\' to quote `$', `\' and ``'. Com- | |
605 | mands that are substituted have all blanks, tabs, and new- | |
606 | lines preserved, except for the final newline which is | |
607 | dropped. The resultant text is placed in an anonymous tem- | |
608 | porary file that is given to the command as its standard | |
609 | input. | |
610 | > name | |
611 | >! name | |
612 | >& name | |
613 | >&! name | |
614 | The file _\bn_\ba_\bm_\be is used as the standard output. If the file | |
615 | does not exist then it is created; if the file exists, it | |
616 | is truncated; its previous contents are lost. | |
617 | ||
618 | If the variable _\bn_\bo_\bc_\bl_\bo_\bb_\bb_\be_\br is set, then the file must not | |
619 | exist or be a character special file (e.g., a terminal or | |
620 | `/dev/null') or an error results. This helps prevent acci- | |
621 | dental destruction of files. Here, the `!' forms can be | |
622 | used to suppress this check. | |
623 | ||
624 | The forms involving `&' route the standard error output in- | |
625 | to the specified file as well as the standard output. _\bN_\ba_\bm_\be | |
626 | is expanded in the same way as `<' input filenames are. | |
627 | >> name | |
628 | >>& name | |
629 | >>! name | |
630 | >>&! name | |
631 | Uses file _\bn_\ba_\bm_\be as the standard output; like `>' but places | |
632 | output at the end of the file. If the variable _\bn_\bo_\bc_\bl_\bo_\bb_\bb_\be_\br | |
633 | is set, then it is an error for the file not to exist un- | |
634 | less one of the `!' forms is given. Otherwise similar to | |
635 | `>'. | |
636 | ||
637 | A command receives the environment in which the shell was invoked as mod- | |
638 | ified by the input-output parameters and the presence of the command in a | |
639 | pipeline. Thus, unlike some previous shells, commands run from a file of | |
640 | shell commands have no access to the text of the commands by default; in- | |
641 | stead they receive the original standard input of the shell. The `<<' | |
642 | mechanism should be used to present inline data. This permits shell com- | |
643 | mand scripts to function as components of pipelines and allows the shell | |
644 | to block read its input. Note that the default standard input for a com- | |
645 | mand run detached is _\bn_\bo_\bt modified to be the empty file _\b/_\bd_\be_\bv_\b/_\bn_\bu_\bl_\bl; instead | |
646 | the standard input remains as the original standard input of the shell. | |
647 | If this is a terminal and if the process attempts to read from the termi- | |
648 | nal, then the process will block and the user will be notified (see _\bJ_\bo_\bb_\bs | |
649 | above). | |
650 | ||
651 | The standard error output may be directed through a pipe with the stan- | |
652 | dard output. Simply use the form `|&' instead of just `|'. | |
653 | ||
654 | E\bEx\bxp\bpr\bre\bes\bss\bsi\bio\bon\bns\bs | |
655 | Several of the builtin commands (to be described later) take expressions, | |
656 | in which the operators are similar to those of C, with the same prece- | |
657 | dence. These expressions appear in the @\b@,\b, _\be_\bx_\bi_\bt, _\bi_\bf, and _\bw_\bh_\bi_\bl_\be commands. | |
658 | The following operators are available: | |
659 | ||
660 | || && | ^ & == != =~ !~ <= >= < > << >> + - * / % | |
661 | ! ~ ( ) | |
662 | ||
663 | Here the precedence increases to the right, `==' `!=' `=~' and `!~', `<=' | |
664 | `>=' `<' and `>', `<<' and `>>', `+' and `-', `*' `/' and `%' being, in | |
665 | groups, at the same level. The `==' `!=' `=~' and `!~' operators compare | |
666 | their arguments as strings; all others operate on numbers. The operators | |
667 | `=~' and `!~' are like `!=' and `==' except that the right hand side is a | |
668 | _\bp_\ba_\bt_\bt_\be_\br_\bn (containing, e.g., `*'s, `?'s and instances of `[...]') against | |
669 | which the left hand operand is matched. This reduces the need for use of | |
670 | the _\bs_\bw_\bi_\bt_\bc_\bh statement in shell scripts when all that is really needed is | |
671 | pattern matching. | |
672 | ||
673 | Strings that begin with `0' are considered octal numbers. Null or miss- | |
674 | ing arguments are considered `0'. The result of all expressions are | |
675 | strings, which represent decimal numbers. It is important to note that | |
676 | no two components of an expression can appear in the same word; except | |
677 | when adjacent to components of expressions that are syntactically signif- | |
678 | icant to the parser (`&' `|' `<' `>' `(' `)'), they should be surrounded | |
679 | by spaces. | |
680 | ||
681 | Also available in expressions as primitive operands are command execu- | |
682 | tions enclosed in `{' and `}' and file enquiries of the form -\b-l\bl _\bn_\ba_\bm_\be | |
683 | where l\bl is one of: | |
684 | ||
685 | r read access | |
686 | w write access | |
687 | x execute access | |
688 | e existence | |
689 | o ownership | |
690 | z zero size | |
691 | f plain file | |
692 | d directory | |
693 | ||
694 | The specified name is command and filename expanded and then tested to | |
695 | see if it has the specified relationship to the real user. If the file | |
696 | does not exist or is inaccessible then all enquiries return false, i.e., | |
697 | `0'. Command executions succeed, returning true, i.e., `1', if the com- | |
698 | mand exits with status 0, otherwise they fail, returning false, i.e., | |
699 | `0'. If more detailed status information is required then the command | |
700 | should be executed outside an expression and the variable _\bs_\bt_\ba_\bt_\bu_\bs exam- | |
701 | ined. | |
702 | ||
703 | C\bCo\bon\bnt\btr\bro\bol\bl f\bfl\blo\bow\bw | |
704 | The shell contains several commands that can be used to regulate the flow | |
705 | of control in command files (shell scripts) and (in limited but useful | |
706 | ways) from terminal input. These commands all operate by forcing the | |
707 | shell to reread or skip in its input and, because of the implementation, | |
708 | restrict the placement of some of the commands. | |
709 | ||
710 | The f\bfo\bor\bre\bea\bac\bch\bh, s\bsw\bwi\bit\btc\bch\bh, and w\bwh\bhi\bil\ble\be statements, as well as the i\bif\bf-\b-t\bth\bhe\ben\bn-\b-e\bel\bls\bse\be | |
711 | form of the i\bif\bf statement require that the major keywords appear in a sin- | |
712 | gle simple command on an input line as shown below. | |
713 | ||
714 | If the shell's input is not seekable, the shell buffers up input whenever | |
715 | a loop is being read and performs seeks in this internal buffer to accom- | |
716 | plish the rereading implied by the loop. (To the extent that this al- | |
717 | lows, backward goto's will succeed on non-seekable inputs.) | |
718 | ||
719 | B\bBu\bui\bil\blt\bti\bin\bn c\bco\bom\bmm\bma\ban\bnd\bds\bs | |
720 | Builtin commands are executed within the shell. If a builtin command oc- | |
721 | curs as any component of a pipeline except the last then it is executed | |
722 | in a subshell. | |
723 | ||
724 | a\bal\bli\bia\bas\bs | |
725 | a\bal\bli\bia\bas\bs _\bn_\ba_\bm_\be | |
726 | ||
727 | a\bal\bli\bia\bas\bs _\bn_\ba_\bm_\be _\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt | |
728 | The first form prints all aliases. The second form prints | |
729 | the alias for name. The final form assigns the specified | |
730 | _\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt as the alias of _\bn_\ba_\bm_\be; _\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt is command and | |
731 | filename substituted. _\bN_\ba_\bm_\be is not allowed to be _\ba_\bl_\bi_\ba_\bs or | |
732 | _\bu_\bn_\ba_\bl_\bi_\ba_\bs. | |
733 | ||
734 | a\bal\bll\blo\boc\bc Shows the amount of dynamic memory acquired, broken down | |
735 | into used and free memory. With an argument shows the num- | |
736 | ber of free and used blocks in each size category. The | |
737 | categories start at size 8 and double at each step. This | |
738 | command's output may vary across system types, since sys- | |
739 | tems other than the VAX may use a different memory alloca- | |
740 | tor. | |
741 | ||
742 | b\bbg\bg | |
743 | b\bbg\bg %\b%_\bj_\bo_\bb _\b._\b._\b. | |
744 | Puts the current or specified jobs into the background, | |
745 | continuing them if they were stopped. | |
746 | ||
747 | b\bbr\bre\bea\bak\bk Causes execution to resume after the e\ben\bnd\bd of the nearest en- | |
748 | closing f\bfo\bor\bre\bea\bac\bch\bh or w\bwh\bhi\bil\ble\be. The remaining commands on the | |
749 | current line are executed. Multi-level breaks are thus | |
750 | possible by writing them all on one line. | |
751 | ||
752 | b\bbr\bre\bea\bak\bks\bsw\bw | |
753 | Causes a break from a s\bsw\bwi\bit\btc\bch\bh, resuming after the e\ben\bnd\bds\bsw\bw. | |
754 | ||
755 | c\bca\bas\bse\be _\bl_\ba_\bb_\be_\bl: | |
756 | A label in a s\bsw\bwi\bit\btc\bch\bh statement as discussed below. | |
757 | ||
758 | c\bcd\bd | |
759 | c\bcd\bd _\bn_\ba_\bm_\be | |
760 | c\bch\bhd\bdi\bir\br | |
761 | c\bch\bhd\bdi\bir\br _\bn_\ba_\bm_\be | |
762 | Change the shell's working directory to directory _\bn_\ba_\bm_\be. If | |
763 | no argument is given then change to the home directory of | |
764 | the user. If _\bn_\ba_\bm_\be is not found as a subdirectory of the | |
765 | current directory (and does not begin with `/', `./' or | |
766 | `../'), then each component of the variable c\bcd\bdp\bpa\bat\bth\bh is | |
767 | checked to see if it has a subdirectory _\bn_\ba_\bm_\be. Finally, if | |
768 | all else fails but _\bn_\ba_\bm_\be is a shell variable whose value be- | |
769 | gins with `/', then this is tried to see if it is a direc- | |
770 | tory. | |
771 | ||
772 | c\bco\bon\bnt\bti\bin\bnu\bue\be | |
773 | Continue execution of the nearest enclosing w\bwh\bhi\bil\ble\be or | |
774 | f\bfo\bor\bre\bea\bac\bch\bh. The rest of the commands on the current line are | |
775 | executed. | |
776 | ||
777 | d\bde\bef\bfa\bau\bul\blt\bt: | |
778 | Labels the default case in a s\bsw\bwi\bit\btc\bch\bh statement. The default | |
779 | should come after all c\bca\bas\bse\be labels. | |
780 | ||
781 | d\bdi\bir\brs\bs Prints the directory stack; the top of the stack is at the | |
782 | left, the first directory in the stack being the current | |
783 | directory. | |
784 | ||
785 | e\bec\bch\bho\bo _\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt | |
786 | e\bec\bch\bho\bo -\b-n\bn _\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt | |
787 | The specified words are written to the shell's standard | |
788 | output, separated by spaces, and terminated with a newline | |
789 | unless the -\b-n\bn option is specified. | |
790 | ||
791 | e\bel\bls\bse\be | |
792 | ||
793 | ||
794 | e\ben\bnd\bd | |
795 | e\ben\bnd\bdi\bif\bf | |
796 | e\ben\bnd\bds\bsw\bw See the description of the f\bfo\bor\bre\bea\bac\bch\bh, i\bif\bf, s\bsw\bwi\bit\btc\bch\bh, and w\bwh\bhi\bil\ble\be | |
797 | statements below. | |
798 | ||
799 | e\bev\bva\bal\bl _\ba_\br_\bg _\b._\b._\b. | |
800 | (As in sh(1).) The arguments are read as input to the | |
801 | shell and the resulting command(s) executed in the context | |
802 | of the current shell. This is usually used to execute com- | |
803 | mands generated as the result of command or variable sub- | |
804 | stitution, since parsing occurs before these substitutions. | |
805 | See tset(1) for an example of using e\bev\bva\bal\bl. | |
806 | ||
807 | e\bex\bxe\bec\bc _\bc_\bo_\bm_\bm_\ba_\bn_\bd | |
808 | The specified command is executed in place of the current | |
809 | shell. | |
810 | ||
811 | e\bex\bxi\bit\bt | |
812 | e\bex\bxi\bit\bt _\b(_\be_\bx_\bp_\br) | |
813 | The shell exits either with the value of the s\bst\bta\bat\btu\bus\bs vari- | |
814 | able (first form) or with the value of the specified e\bex\bxp\bpr\br | |
815 | (second form). | |
816 | ||
817 | f\bfg\bg | |
818 | f\bfg\bg %\b%_\bj_\bo_\bb _\b._\b._\b. | |
819 | Brings the current or specified jobs into the foreground, | |
820 | continuing them if they were stopped. | |
821 | ||
822 | f\bfo\bor\bre\bea\bac\bch\bh _\bn_\ba_\bm_\be _\b(_\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt_\b) | |
823 | ... | |
824 | e\ben\bnd\bd The variable n\bna\bam\bme\be is successively set to each member of | |
825 | w\bwo\bor\brd\bdl\bli\bis\bst\bt and the sequence of commands between this command | |
826 | and the matching e\ben\bnd\bd are executed. (Both f\bfo\bor\bre\bea\bac\bch\bh and e\ben\bnd\bd | |
827 | must appear alone on separate lines.) The builtin command | |
828 | c\bco\bon\bnt\bti\bin\bnu\bue\be may be used to continue the loop prematurely and | |
829 | the builtin command b\bbr\bre\bea\bak\bk to terminate it prematurely. | |
830 | When this command is read from the terminal, the loop is | |
831 | read once prompting with `?' before any statements in the | |
832 | loop are executed. If you make a mistake typing in a loop | |
833 | at the terminal you can rub it out. | |
834 | ||
835 | g\bgl\blo\bob\bb _\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt | |
836 | Like e\bec\bch\bho\bo but no `\' escapes are recognized and words are | |
837 | delimited by null characters in the output. Useful for | |
838 | programs that wish to use the shell to filename expand a | |
839 | list of words. | |
840 | ||
841 | g\bgo\bot\bto\bo _\bw_\bo_\br_\bd | |
842 | The specified w\bwo\bor\brd\bd is filename and command expanded to | |
843 | yield a string of the form `label'. The shell rewinds its | |
844 | input as much as possible and searches for a line of the | |
845 | form `label:' possibly preceded by blanks or tabs. Execu- | |
846 | tion continues after the specified line. | |
847 | ||
848 | h\bha\bas\bsh\bhs\bst\bta\bat\bt | |
849 | Print a statistics line showing how effective the internal | |
850 | hash table has been at locating commands (and avoiding | |
851 | e\bex\bxe\bec\bc's). An e\bex\bxe\bec\bc is attempted for each component of the | |
852 | _\bp_\ba_\bt_\bh where the hash function indicates a possible hit, and | |
853 | in each component that does not begin with a `/'. | |
854 | ||
855 | h\bhi\bis\bst\bto\bor\bry\by | |
856 | h\bhi\bis\bst\bto\bor\bry\by _\bn | |
857 | h\bhi\bis\bst\bto\bor\bry\by -\b-r\br _\bn | |
858 | h\bhi\bis\bst\bto\bor\bry\by -\b-h\bh _\bn | |
859 | Displays the history event list; if _\bn is given only the _\bn | |
860 | most recent events are printed. The -\b-r\br option reverses the | |
861 | order of printout to be most recent first instead of oldest | |
862 | first. The -\b-h\bh option causes the history list to be printed | |
863 | without leading numbers. This format produces files suit- | |
864 | able for sourcing using the -h option to s\bso\bou\bur\brc\bce\be. | |
865 | ||
866 | i\bif\bf (_\be_\bx_\bp_\br) command | |
867 | If the specified expression evaluates true, then the single | |
868 | _\bc_\bo_\bm_\bm_\ba_\bn_\bd with arguments is executed. Variable substitution | |
869 | on _\bc_\bo_\bm_\bm_\ba_\bn_\bd happens early, at the same time it does for the | |
870 | rest of the i\bif\bf command. _\bC_\bo_\bm_\bm_\ba_\bn_\bd must be a simple command, | |
871 | not a pipeline, a command list, or a parenthesized command | |
872 | list. Input/output redirection occurs even if _\be_\bx_\bp_\br is | |
873 | false, i.e., when command is n\bno\bot\bt executed (this is a bug). | |
874 | ||
875 | i\bif\bf (_\be_\bx_\bp_\br) t\bth\bhe\ben\bn | |
876 | ... | |
877 | e\bel\bls\bse\be i\bif\bf (_\be_\bx_\bp_\br_\b2) t\bth\bhe\ben\bn | |
878 | ... | |
879 | e\bel\bls\bse\be | |
880 | ... | |
881 | e\ben\bnd\bdi\bif\bf If the specified _\be_\bx_\bp_\br is true then the commands up to the | |
882 | first e\bel\bls\bse\be are executed; otherwise if _\be_\bx_\bp_\br_\b2 is true then | |
883 | the commands up to the second e\bel\bls\bse\be are executed, etc. Any | |
884 | number of e\bel\bls\bse\be-\b-i\bif\bf pairs are possible; only one e\ben\bnd\bdi\bif\bf is | |
885 | needed. The e\bel\bls\bse\be part is likewise optional. (The words | |
886 | e\bel\bls\bse\be and e\ben\bnd\bdi\bif\bf must appear at the beginning of input lines; | |
887 | the i\bif\bf must appear alone on its input line or after an | |
888 | e\bel\bls\bse\be.) | |
889 | ||
890 | j\bjo\bob\bbs\bs | |
891 | j\bjo\bob\bbs\bs -\b-l\bl | |
892 | Lists the active jobs; the -\b-l\bl option lists process id's in | |
893 | addition to the normal information. | |
894 | ||
895 | k\bki\bil\bll\bl %\b%_\bj_\bo_\bb | |
896 | k\bki\bil\bll\bl _\bp_\bi_\bd | |
897 | k\bki\bil\bll\bl -\b-s\bsi\big\bg _\bp_\bi_\bd _\b._\b._\b. | |
898 | k\bki\bil\bll\bl -\b-l\bl | |
899 | Sends either the TERM (terminate) signal or the specified | |
900 | signal to the specified jobs or processes. Signals are ei- | |
901 | ther given by number or by names (as given in | |
902 | _\b/_\bu_\bs_\br_\b/_\bi_\bn_\bc_\bl_\bu_\bd_\be_\b/_\bs_\bi_\bg_\bn_\ba_\bl_\b._\bh_\b, stripped of the prefix ``SIG''). | |
903 | The signal names are listed by ``kill -l''. There is no | |
904 | default, just saying `kill' does not send a signal to the | |
905 | current job. If the signal being sent is TERM (terminate) | |
906 | or HUP (hangup), then the job or process will be sent a | |
907 | CONT (continue) signal as well. | |
908 | ||
909 | l\bli\bim\bmi\bit\bt | |
910 | l\bli\bim\bmi\bit\bt _\br_\be_\bs_\bo_\bu_\br_\bc_\be | |
911 | l\bli\bim\bmi\bit\bt _\br_\be_\bs_\bo_\bu_\br_\bc_\be _\bm_\ba_\bx_\bi_\bm_\bu_\bm_\b-_\bu_\bs_\be | |
912 | l\bli\bim\bmi\bit\bt -\b-h\bh | |
913 | l\bli\bim\bmi\bit\bt -\b-h\bh _\br_\be_\bs_\bo_\bu_\br_\bc_\be | |
914 | l\bli\bim\bmi\bit\bt -\b-h\bh _\br_\be_\bs_\bo_\bu_\br_\bc_\be _\bm_\ba_\bx_\bi_\bm_\bu_\bm_\b-_\bu_\bs_\be | |
915 | Limits the consumption by the current process and each pro- | |
916 | cess it creates to not individually exceed _\bm_\ba_\bx_\bi_\bm_\bu_\bm_\b-_\bu_\bs_\be on | |
917 | the specified _\br_\be_\bs_\bo_\bu_\br_\bc_\be. If no _\bm_\ba_\bx_\bi_\bm_\bu_\bm_\b-_\bu_\bs_\be is given, then | |
918 | the current limit is printed; if no _\br_\be_\bs_\bo_\bu_\br_\bc_\be is given, then | |
919 | all limitations are given. If the -\b-h\bh flag is given, the | |
920 | hard limits are used instead of the current limits. The | |
921 | hard limits impose a ceiling on the values of the current | |
922 | limits. Only the super-user may raise the hard limits, but | |
923 | a user may lower or raise the current limits within the le- | |
924 | gal range. | |
925 | ||
926 | Resources controllable currently include _\bc_\bp_\bu_\bt_\bi_\bm_\be (the maxi- | |
927 | mum number of cpu-seconds to be used by each process), | |
928 | _\bf_\bi_\bl_\be_\bs_\bi_\bz_\be (the largest single file that can be created), | |
929 | _\bd_\ba_\bt_\ba_\bs_\bi_\bz_\be (the maximum growth of the data+stack region via | |
930 | sbrk(2) beyond the end of the program text), _\bs_\bt_\ba_\bc_\bk_\bs_\bi_\bz_\be (the | |
931 | maximum size of the automatically-extended stack region), | |
932 | and _\bc_\bo_\br_\be_\bd_\bu_\bm_\bp_\bs_\bi_\bz_\be (the size of the largest core dump that | |
933 | will be created). (.ne 1i | |
934 | ||
935 | The _\bm_\ba_\bx_\bi_\bm_\bu_\bm_\b-_\bu_\bs_\be may be given as a (floating point or inte- | |
936 | ger) number followed by a scale factor. For all limits | |
937 | other than _\bc_\bp_\bu_\bt_\bi_\bm_\be the default scale is `k' or `kilobytes' | |
938 | (1024 bytes); a scale factor of `m' or `megabytes' may also | |
939 | be used. For _\bc_\bp_\bu_\bt_\bi_\bm_\be the default scale is `seconds'; a | |
940 | scale factor of `m' for minutes or `h' for hours, or a time | |
941 | of the form `mm:ss' giving minutes and seconds also may be | |
942 | used. | |
943 | ||
944 | For both _\br_\be_\bs_\bo_\bu_\br_\bc_\be names and scale factors, unambiguous pre- | |
945 | fixes of the names suffice. | |
946 | ||
947 | l\blo\bog\bgi\bin\bn Terminate a login shell, replacing it with an instance of | |
948 | _\b/_\bb_\bi_\bn_\b/_\bl_\bo_\bg_\bi_\bn_\b. This is one way to log off, included for com- | |
949 | patibility with sh(1). | |
950 | ||
951 | l\blo\bog\bgo\bou\but\bt Terminate a login shell. Especially useful if i\big\bgn\bno\bor\bre\bee\beo\bof\bf is | |
952 | set. | |
953 | ||
954 | n\bni\bic\bce\be | |
955 | n\bni\bic\bce\be _\b+_\bn_\bu_\bm_\bb_\be_\br | |
956 | n\bni\bic\bce\be _\bc_\bo_\bm_\bm_\ba_\bn_\bd | |
957 | n\bni\bic\bce\be _\b+_\bn_\bu_\bm_\bb_\be_\br _\bc_\bo_\bm_\bm_\ba_\bn_\bd | |
958 | The first form sets the scheduling priority for this shell | |
959 | to 4. The second form sets the priority to the given | |
960 | _\bn_\bu_\bm_\bb_\be_\br. The final two forms run command at priority 4 and | |
961 | _\bn_\bu_\bm_\bb_\be_\br respectively. The greater the number, the less cpu | |
962 | the process will get. The super-user may specify negative | |
963 | priority by using `nice -number ...'. _\bC_\bo_\bm_\bm_\ba_\bn_\bd is always | |
964 | executed in a sub-shell, and the restrictions placed on | |
965 | commands in simple i\bif\bf statements apply. | |
966 | ||
967 | n\bno\boh\bhu\bup\bp | |
968 | n\bno\boh\bhu\bup\bp _\bc_\bo_\bm_\bm_\ba_\bn_\bd | |
969 | The first form can be used in shell scripts to cause | |
970 | hangups to be ignored for the remainder of the script. The | |
971 | second form causes the specified command to be run with | |
972 | hangups ignored. All processes detached with `&' are ef- | |
973 | fectively n\bno\boh\bhu\bup\bp'ed. | |
974 | ||
975 | n\bno\bot\bti\bif\bfy\by | |
976 | n\bno\bot\bti\bif\bfy\by %\b%_\bj_\bo_\bb _\b._\b._\b. | |
977 | Causes the shell to notify the user asynchronously when the | |
978 | status of the current or specified jobs change; normally | |
979 | notification is presented before a prompt. This is auto- | |
980 | matic if the shell variable n\bno\bot\bti\bif\bfy\by is set. | |
981 | ||
982 | o\bon\bni\bin\bnt\btr\br | |
983 | o\bon\bni\bin\bnt\btr\br -\b- | |
984 | o\bon\bni\bin\bnt\btr\br _\bl_\ba_\bb_\be_\bl | |
985 | Control the action of the shell on interrupts. The first | |
986 | form restores the default action of the shell on interrupts | |
987 | which is to terminate shell scripts or to return to the | |
988 | terminal command input level. The second form `onintr -' | |
989 | causes all interrupts to be ignored. The final form causes | |
990 | the shell to execute a `goto label' when an interrupt is | |
991 | received or a child process terminates because it was in- | |
992 | terrupted. | |
993 | ||
994 | ||
995 | In any case, if the shell is running detached and inter- | |
996 | rupts are being ignored, all forms of o\bon\bni\bin\bnt\btr\br have no mean- | |
997 | ing and interrupts continue to be ignored by the shell and | |
998 | all invoked commands. Finally o\bon\bni\bin\bnt\btr\br statements are ig- | |
999 | nored in the system startup files where interrupts are dis- | |
1000 | abled (/etc/csh.cshrc, /etc/csh.login). | |
1001 | ||
1002 | p\bpo\bop\bpd\bd | |
1003 | p\bpo\bop\bpd\bd _\b+_\bn | |
1004 | Pops the directory stack, returning to the new top directo- | |
1005 | ry. With an argument `+ _\bn' discards the _\bn'th entry in the | |
1006 | stack. The members of the directory stack are numbered | |
1007 | from the top starting at 0. | |
1008 | ||
1009 | p\bpu\bus\bsh\bhd\bd | |
1010 | p\bpu\bus\bsh\bhd\bd _\bn_\ba_\bm_\be | |
1011 | p\bpu\bus\bsh\bhd\bd _\bn | |
1012 | With no arguments, p\bpu\bus\bsh\bhd\bd exchanges the top two elements of | |
1013 | the directory stack. Given a _\bn_\ba_\bm_\be argument, p\bpu\bus\bsh\bhd\bd changes | |
1014 | to the new directory (ala c\bcd\bd) and pushes the old current | |
1015 | working directory (as in c\bcs\bsw\bw) onto the directory stack. | |
1016 | With a numeric argument, p\bpu\bus\bsh\bhd\bd rotates the _\bn'th argument of | |
1017 | the directory stack around to be the top element and | |
1018 | changes to it. The members of the directory stack are num- | |
1019 | bered from the top starting at 0. | |
1020 | ||
1021 | r\bre\beh\bha\bas\bsh\bh Causes the internal hash table of the contents of the di- | |
1022 | rectories in the p\bpa\bat\bth\bh variable to be recomputed. This is | |
1023 | needed if new commands are added to directories in the p\bpa\bat\bth\bh | |
1024 | while you are logged in. This should only be necessary if | |
1025 | you add commands to one of your own directories, or if a | |
1026 | systems programmer changes the contents of a system direc- | |
1027 | tory. | |
1028 | ||
1029 | r\bre\bep\bpe\bea\bat\bt _\bc_\bo_\bu_\bn_\bt _\bc_\bo_\bm_\bm_\ba_\bn_\bd | |
1030 | The specified _\bc_\bo_\bm_\bm_\ba_\bn_\bd which is subject to the same restric- | |
1031 | tions as the _\bc_\bo_\bm_\bm_\ba_\bn_\bd in the one line i\bif\bf statement above, is | |
1032 | executed _\bc_\bo_\bu_\bn_\bt times. I/O redirections occur exactly once, | |
1033 | even if _\bc_\bo_\bu_\bn_\bt is 0. | |
1034 | ||
1035 | s\bse\bet\bt | |
1036 | s\bse\bet\bt _\bn_\ba_\bm_\be | |
1037 | s\bse\bet\bt _\bn_\ba_\bm_\be=word | |
1038 | s\bse\bet\bt _\bn_\ba_\bm_\be_\b[_\bi_\bn_\bd_\be_\bx_\b]=word | |
1039 | s\bse\bet\bt _\bn_\ba_\bm_\be=(wordlist) | |
1040 | The first form of the command shows the value of all shell | |
1041 | variables. Variables that have other than a single word as | |
1042 | their value print as a parenthesized word list. The second | |
1043 | form sets _\bn_\ba_\bm_\be to the null string. The third form sets | |
1044 | _\bn_\ba_\bm_\be to the single _\bw_\bo_\br_\bd. The fourth form sets the _\bi_\bn_\bd_\be_\bx'th | |
1045 | component of _\bn_\ba_\bm_\be to _\bw_\bo_\br_\bd; this component must already ex- | |
1046 | ist. The final form sets _\bn_\ba_\bm_\be to the list of words in | |
1047 | _\bw_\bo_\br_\bd_\bl_\bi_\bs_\bt. The value is always command and filename expand- | |
1048 | ed. | |
1049 | ||
1050 | These arguments may be repeated to set multiple values in a | |
1051 | single set command. Note however, that variable expansion | |
1052 | happens for all arguments before any setting occurs. | |
1053 | ||
1054 | s\bse\bet\bte\ben\bnv\bv | |
1055 | s\bse\bet\bte\ben\bnv\bv _\bn_\ba_\bm_\be | |
1056 | s\bse\bet\bte\ben\bnv\bv _\bn_\ba_\bm_\be _\bv_\ba_\bl_\bu_\be | |
1057 | The first form lists all current environment variables. It | |
1058 | is equivalent to printenv(1). The last form sets the value | |
1059 | of environment variable _\bn_\ba_\bm_\be to be _\bv_\ba_\bl_\bu_\be, a single string. | |
1060 | The second form sets _\bn_\ba_\bm_\be to an empty string. The most | |
1061 | commonly used environment variables USER, TERM, and PATH | |
1062 | are automatically imported to and exported from the c\bcs\bsh\bh | |
1063 | variables _\bu_\bs_\be_\br, _\bt_\be_\br_\bm, and _\bp_\ba_\bt_\bh; there is no need to use | |
1064 | s\bse\bet\bte\ben\bnv\bv for these. | |
1065 | ||
1066 | s\bsh\bhi\bif\bft\bt | |
1067 | s\bsh\bhi\bif\bft\bt _\bv_\ba_\br_\bi_\ba_\bb_\bl_\be | |
1068 | The members of a\bar\brg\bgv\bv are shifted to the left, discarding | |
1069 | a\bar\brg\bgv\bv[1]. It is an error for a\bar\brg\bgv\bv not to be set or to have | |
1070 | less than one word as value. The second form performs the | |
1071 | same function on the specified variable. | |
1072 | ||
1073 | s\bso\bou\bur\brc\bce\be _\bn_\ba_\bm_\be | |
1074 | s\bso\bou\bur\brc\bce\be -\b-h\bh _\bn_\ba_\bm_\be | |
1075 | The shell reads commands from _\bn_\ba_\bm_\be. S\bSo\bou\bur\brc\bce\be commands may be | |
1076 | nested; if they are nested too deeply the shell may run out | |
1077 | of file descriptors. An error in a s\bso\bou\bur\brc\bce\be at any level | |
1078 | terminates all nested s\bso\bou\bur\brc\bce\be commands. Normally input dur- | |
1079 | ing s\bso\bou\bur\brc\bce\be commands is not placed on the history list; the | |
1080 | -h option causes the commands to be placed on the history | |
1081 | list without being executed. | |
1082 | ||
1083 | s\bst\bto\bop\bp | |
1084 | s\bst\bto\bop\bp %\b%_\bj_\bo_\bb _\b._\b._\b. | |
1085 | Stops the current or specified jobs that are executing in | |
1086 | the background. | |
1087 | ||
1088 | s\bsu\bus\bsp\bpe\ben\bnd\bd | |
1089 | Causes the shell to stop in its tracks, much as if it had | |
1090 | been sent a stop signal with ^\b^Z\bZ. This is most often used to | |
1091 | stop shells started by su(1). | |
1092 | ||
1093 | s\bsw\bwi\bit\btc\bch\bh _\b(_\bs_\bt_\br_\bi_\bn_\bg_\b) | |
1094 | c\bca\bas\bse\be _\bs_\bt_\br_\b1: | |
1095 | ... | |
1096 | b\bbr\bre\bea\bak\bks\bsw\bw | |
1097 | ... | |
1098 | d\bde\bef\bfa\bau\bul\blt\bt: | |
1099 | ... | |
1100 | b\bbr\bre\bea\bak\bks\bsw\bw | |
1101 | e\ben\bnd\bds\bsw\bw Each case label is successively matched against the speci- | |
1102 | fied _\bs_\bt_\br_\bi_\bn_\bg which is first command and filename expanded. | |
1103 | The file metacharacters `*', `?' and `[...]' may be used | |
1104 | in the case labels, which are variable expanded. If none | |
1105 | of the labels match before the `default' label is found, | |
1106 | then the execution begins after the default label. Each | |
1107 | case label and the default label must appear at the begin- | |
1108 | ning of a line. The command b\bbr\bre\bea\bak\bks\bsw\bw causes execution to | |
1109 | continue after the e\ben\bnd\bds\bsw\bw. Otherwise control may fall | |
1110 | through case labels and the default label as in C. If no | |
1111 | label matches and there is no default, execution continues | |
1112 | after the e\ben\bnd\bds\bsw\bw. | |
1113 | ||
1114 | t\bti\bim\bme\be | |
1115 | t\bti\bim\bme\be _\bc_\bo_\bm_\bm_\ba_\bn_\bd | |
1116 | With no argument, a summary of time used by this shell and | |
1117 | its children is printed. If arguments are given the speci- | |
1118 | fied simple command is timed and a time summary as de- | |
1119 | scribed under the t\bti\bim\bme\be variable is printed. If necessary, | |
1120 | an extra shell is created to print the time statistic when | |
1121 | the command completes. | |
1122 | ||
1123 | u\bum\bma\bas\bsk\bk | |
1124 | u\bum\bma\bas\bsk\bk _\bv_\ba_\bl_\bu_\be | |
1125 | The file creation mask is displayed (first form) or set to | |
1126 | the specified value (second form). The mask is given in | |
1127 | octal. Common values for the mask are 002 giving all ac- | |
1128 | cess to the group and read and execute access to others or | |
1129 | 022 giving all access except write access for users in the | |
1130 | group or others. | |
1131 | ||
1132 | u\bun\bna\bal\bli\bia\bas\bs _\bp_\ba_\bt_\bt_\be_\br_\bn | |
1133 | All aliases whose names match the specified pattern are | |
1134 | discarded. Thus all aliases are removed by `unalias *'. | |
1135 | It is not an error for nothing to be u\bun\bna\bal\bli\bia\bas\bse\bed\bd. | |
1136 | ||
1137 | u\bun\bnh\bha\bas\bsh\bh Use of the internal hash table to speed location of execut- | |
1138 | ed programs is disabled. | |
1139 | ||
1140 | u\bun\bnl\bli\bim\bmi\bit\bt | |
1141 | u\bun\bnl\bli\bim\bmi\bit\bt _\br_\be_\bs_\bo_\bu_\br_\bc_\be | |
1142 | u\bun\bnl\bli\bim\bmi\bit\bt -\b-h\bh | |
1143 | u\bun\bnl\bli\bim\bmi\bit\bt -\b-h\bh _\br_\be_\bs_\bo_\bu_\br_\bc_\be | |
1144 | Removes the limitation on _\br_\be_\bs_\bo_\bu_\br_\bc_\be. If no _\br_\be_\bs_\bo_\bu_\br_\bc_\be is spec- | |
1145 | ified, then all _\br_\be_\bs_\bo_\bu_\br_\bc_\be limitations are removed. If -\b-h\bh is | |
1146 | given, the corresponding hard limits are removed. Only the | |
1147 | super-user may do this. | |
1148 | ||
1149 | u\bun\bns\bse\bet\bt _\bp_\ba_\bt_\bt_\be_\br_\bn | |
1150 | All variables whose names match the specified pattern are | |
1151 | removed. Thus all variables are removed by `unset *'; this | |
1152 | has noticeably distasteful side-effects. It is not an er- | |
1153 | ror for nothing to be u\bun\bns\bse\bet\bt. | |
1154 | ||
1155 | u\bun\bns\bse\bet\bte\ben\bnv\bv _\bp_\ba_\bt_\bt_\be_\br_\bn | |
1156 | Removes all variables whose name match the specified pat- | |
1157 | tern from the environment. See also the s\bse\bet\bte\ben\bnv\bv command | |
1158 | above and printenv(1). | |
1159 | ||
1160 | w\bwa\bai\bit\bt Wait for all background jobs. If the shell is interactive, | |
1161 | then an interrupt can disrupt the wait. After the inter- | |
1162 | rupt, the shell prints names and job numbers of all jobs | |
1163 | known to be outstanding. | |
1164 | w\bwh\bhi\bic\bch\bh _\bc_\bo_\bm_\bm_\ba_\bn_\bd | |
1165 | Displays the resolved command that will be executed by the | |
1166 | shell. | |
1167 | ||
1168 | w\bwh\bhi\bil\ble\be _\b(_\be_\bx_\bp_\br_\b) | |
1169 | ... | |
1170 | e\ben\bnd\bd While the specified expression evaluates non-zero, the com- | |
1171 | mands between the w\bwh\bhi\bil\ble\be and the matching e\ben\bnd\bd are evaluated. | |
1172 | B\bBr\bre\bea\bak\bk and c\bco\bon\bnt\bti\bin\bnu\bue\be may be used to terminate or continue the | |
1173 | loop prematurely. (The w\bwh\bhi\bil\ble\be and e\ben\bnd\bd must appear alone on | |
1174 | their input lines.) Prompting occurs here the first time | |
1175 | through the loop as for the f\bfo\bor\bre\bea\bac\bch\bh statement if the input | |
1176 | is a terminal. | |
1177 | ||
1178 | %\b%_\bj_\bo_\bb Brings the specified job into the foreground. | |
1179 | ||
1180 | %\b%_\bj_\bo_\bb &\b& Continues the specified job in the background. | |
1181 | ||
1182 | @\b@ | |
1183 | @\b@_\bn_\ba_\bm_\be= expr | |
1184 | @\b@_\bn_\ba_\bm_\be_\b[_\bi_\bn_\bd_\be_\bx_\b]= expr | |
1185 | The first form prints the values of all the shell vari- | |
1186 | ables. The second form sets the specified _\bn_\ba_\bm_\be to the val- | |
1187 | ue of _\be_\bx_\bp_\br. If the expression contains `<', `>', `&' or `|' | |
1188 | then at least this part of the expression must be placed | |
1189 | within `(' `)'. The third form assigns the value of _\be_\bx_\bp_\br | |
1190 | to the _\bi_\bn_\bd_\be_\bx'th argument of _\bn_\ba_\bm_\be. Both _\bn_\ba_\bm_\be and its | |
1191 | _\bi_\bn_\bd_\be_\bx'th component must already exist. | |
1192 | ||
1193 | ||
1194 | The operators `*=', `+=', etc are available as in C. The space separat- | |
1195 | ing the name from the assignment operator is optional. Spaces are, how- | |
1196 | ever, mandatory in separating components of _\be_\bx_\bp_\br which would otherwise be | |
1197 | single words. | |
1198 | ||
1199 | Special postfix `++' and `--' operators increment and decrement _\bn_\ba_\bm_\be re- | |
1200 | spectively, i.e., `@ i++'. | |
1201 | ||
1202 | P\bPr\bre\be-\b-d\bde\bef\bfi\bin\bne\bed\bd a\ban\bnd\bd e\ben\bnv\bvi\bir\bro\bon\bnm\bme\ben\bnt\bt v\bva\bar\bri\bia\bab\bbl\ble\bes\bs | |
1203 | The following variables have special meaning to the shell. Of these, | |
1204 | _\ba_\br_\bg_\bv, _\bc_\bw_\bd_\b, _\bh_\bo_\bm_\be, _\bp_\ba_\bt_\bh_\b, _\bp_\br_\bo_\bm_\bp_\bt, _\bs_\bh_\be_\bl_\bl and _\bs_\bt_\ba_\bt_\bu_\bs are always set by the | |
1205 | shell. Except for _\bc_\bw_\bd and _\bs_\bt_\ba_\bt_\bu_\bs, this setting occurs only at initial- | |
1206 | ization; these variables will not then be modified unless done explicitly | |
1207 | by the user. | |
1208 | ||
1209 | The shell copies the environment variable USER into the variable _\bu_\bs_\be_\br, | |
1210 | TERM into _\bt_\be_\br_\bm, and HOME into _\bh_\bo_\bm_\be, and copies these back into the envi- | |
1211 | ronment whenever the normal shell variables are reset. The environment | |
1212 | variable PATH is likewise handled; it is not necessary to worry about its | |
1213 | setting other than in the file _\b._\bc_\bs_\bh_\br_\bc as inferior c\bcs\bsh\bh processes will im- | |
1214 | port the definition of _\bp_\ba_\bt_\bh from the environment, and re-export it if you | |
1215 | then change it. | |
1216 | ||
1217 | a\bar\brg\bgv\bv Set to the arguments to the shell, it is from this variable | |
1218 | that positional parameters are substituted, i.e., `$1' is re- | |
1219 | placed by `$argv[1]', etc. | |
1220 | ||
1221 | c\bcd\bdp\bpa\bat\bth\bh Gives a list of alternate directories searched to find subdi- | |
1222 | rectories in _\bc_\bh_\bd_\bi_\br commands. | |
1223 | ||
1224 | c\bcw\bwd\bd The full pathname of the current directory. | |
1225 | ||
1226 | e\bec\bch\bho\bo Set when the -\b-x\bx command line option is given. Causes each | |
1227 | command and its arguments to be echoed just before it is exe- | |
1228 | cuted. For non-builtin commands all expansions occur before | |
1229 | echoing. Builtin commands are echoed before command and file- | |
1230 | name substitution, since these substitutions are then done se- | |
1231 | lectively. | |
1232 | ||
1233 | f\bfi\bil\ble\bec\bc Enable file name completion. | |
1234 | ||
1235 | h\bhi\bis\bst\btc\bch\bha\bar\brs\bs Can be given a string value to change the characters used in | |
1236 | history substitution. The first character of its value is | |
1237 | used as the history substitution character, replacing the de- | |
1238 | fault character `!'. The second character of its value re- | |
1239 | places the character `|\b^' in quick substitutions. | |
1240 | ||
1241 | h\bhi\bis\bst\btf\bfi\bil\ble\be Can be set to the pathname where history is going to be | |
1242 | saved/restored. | |
1243 | ||
1244 | h\bhi\bis\bst\bto\bor\bry\by Can be given a numeric value to control the size of the histo- | |
1245 | ry list. Any command that has been referenced in this many | |
1246 | events will not be discarded. Too large values of _\bh_\bi_\bs_\bt_\bo_\br_\by may | |
1247 | run the shell out of memory. The last executed command is al- | |
1248 | ways saved on the history list. | |
1249 | ||
1250 | h\bho\bom\bme\be The home directory of the invoker, initialized from the envi- | |
1251 | ronment. The filename expansion of `_\b~' refers to this vari- | |
1252 | able. | |
1253 | ||
1254 | i\big\bgn\bno\bor\bre\bee\beo\bof\bf If set the shell ignores end-of-file from input devices which | |
1255 | are terminals. This prevents shells from accidentally being | |
1256 | killed by control-D's. | |
1257 | ||
1258 | m\bma\bai\bil\bl The files where the shell checks for mail. This checking is | |
1259 | done after each command completion that will result in a | |
1260 | prompt, if a specified interval has elapsed. The shell says | |
1261 | `You have new mail.' if the file exists with an access time | |
1262 | not greater than its modify time. | |
1263 | ||
1264 | If the first word of the value of _\bm_\ba_\bi_\bl is numeric it specifies | |
1265 | a different mail checking interval, in seconds, than the de- | |
1266 | fault, which is 10 minutes. | |
1267 | ||
1268 | If multiple mail files are specified, then the shell says `New | |
1269 | mail in _\bn_\ba_\bm_\be' when there is mail in the file _\bn_\ba_\bm_\be. | |
1270 | ||
1271 | n\bno\boc\bcl\blo\bob\bbb\bbe\ber\br As described in the section on _\bi_\bn_\bp_\bu_\bt_\b/_\bo_\bu_\bt_\bp_\bu_\bt, restrictions are | |
1272 | placed on output redirection to insure that files are not ac- | |
1273 | cidentally destroyed, and that `>>' redirections refer to ex- | |
1274 | isting files. | |
1275 | ||
1276 | n\bno\bog\bgl\blo\bob\bb If set, filename expansion is inhibited. This inhibition is | |
1277 | most useful in shell scripts that | |
1278 | are not dealing with filenames, or after a list of filenames | |
1279 | has been obtained and further expansions are not desirable. | |
1280 | ||
1281 | n\bno\bon\bno\bom\bma\bat\btc\bch\bh If set, it is not an error for a filename expansion to not | |
1282 | match any existing files; instead the primitive pattern is re- | |
1283 | turned. It is still an error for the primitive pattern to be | |
1284 | malformed, i.e., `echo [' still gives an error. | |
1285 | ||
1286 | n\bno\bot\bti\bif\bfy\by If set, the shell notifies asynchronously of job completions; | |
1287 | the default is to present job completions just before printing | |
1288 | a prompt. | |
1289 | ||
1290 | p\bpa\bat\bth\bh Each word of the path variable specifies a directory in which | |
1291 | commands are to be sought for execution. A null word speci- | |
1292 | fies the current directory. If there is no _\bp_\ba_\bt_\bh variable then | |
1293 | only full path names will execute. The usual search path is | |
1294 | `.', `/bin' and `/usr/bin', but this may vary from system to | |
1295 | system. For the super-user the default search path is `/etc', | |
1296 | `/bin' and `/usr/bin'. A shell that is given neither the -\b-c\bc | |
1297 | nor the -\b-t\bt option will normally hash the contents of the di- | |
1298 | rectories in the _\bp_\ba_\bt_\bh variable after reading _\b._\bc_\bs_\bh_\br_\bc, and each | |
1299 | time the _\bp_\ba_\bt_\bh variable is reset. If new commands are added to | |
1300 | these directories while the shell is active, it may be neces- | |
1301 | sary to do a r\bre\beh\bha\bas\bsh\bh or the commands may not be found. | |
1302 | ||
1303 | p\bpr\bro\bom\bmp\bpt\bt The string that is printed before each command is read from an | |
1304 | interactive terminal input. If a `!' appears in the string it | |
1305 | will be replaced by the current event number unless a preced- | |
1306 | ing `\' is given. Default is `% ', or `# ' for the super- | |
1307 | user. | |
1308 | ||
1309 | s\bsa\bav\bve\beh\bhi\bis\bst\bt Is given a numeric value to control the number of entries of | |
1310 | the history list that are saved in ~/.history when the user | |
1311 | logs out. Any command that has been referenced in this many | |
1312 | events will be saved. During start up the shell sources | |
1313 | ~/.history into the history list enabling history to be saved | |
1314 | across logins. Too large values of _\bs_\ba_\bv_\be_\bh_\bi_\bs_\bt will slow down | |
1315 | the shell during start up. If _\bs_\ba_\bv_\be_\bh_\bi_\bs_\bt is just set, the shell | |
1316 | will use the value of _\bh_\bi_\bs_\bt_\bo_\br_\by_\b. | |
1317 | ||
1318 | s\bsh\bhe\bel\bll\bl The file in which the shell resides. This variable is used in | |
1319 | forking shells to interpret files that have execute bits set, | |
1320 | but which are not executable by the system. (See the descrip- | |
1321 | tion of _\bN_\bo_\bn_\b-_\bb_\bu_\bi_\bl_\bt_\bi_\bn _\bC_\bo_\bm_\bm_\ba_\bn_\bd _\bE_\bx_\be_\bc_\bu_\bt_\bi_\bo_\bn below.) Initialized to | |
1322 | the (system-dependent) home of the shell. | |
1323 | ||
1324 | s\bst\bta\bat\btu\bus\bs The status returned by the last command. If it terminated ab- | |
1325 | normally, then 0200 is added to the status. Builtin commands | |
1326 | that fail return exit status `1', all other builtin commands | |
1327 | set status to `0'. | |
1328 | ||
1329 | t\bti\bim\bme\be Controls automatic timing of commands. If set, then any com- | |
1330 | mand that takes more than this many cpu seconds will cause a | |
1331 | line giving user, system, and real times and a utilization | |
1332 | percentage which is the ratio of user plus system times to re- | |
1333 | al time to be printed when it terminates. | |
1334 | ||
1335 | v\bve\ber\brb\bbo\bos\bse\be Set by the -\b-v\bv command line option, causes the words of each | |
1336 | command to be printed after history substitution. | |
1337 | ||
1338 | N\bNo\bon\bn-\b-b\bbu\bui\bil\blt\bti\bin\bn c\bco\bom\bmm\bma\ban\bnd\bd e\bex\bxe\bec\bcu\but\bti\bio\bon\bn | |
1339 | When a command to be executed is found to not be a builtin command the | |
1340 | shell attempts to execute the command via execve(2). Each word in the | |
1341 | variable _\bp_\ba_\bt_\bh names a directory from which the shell will attempt to exe- | |
1342 | cute the command. If it is given neither a -\b-c\bc nor a -\b-t\bt option, the shell | |
1343 | will hash the names in these directories into an internal table so that | |
1344 | it will only try an e\bex\bxe\bec\bc in a directory if there is a possibility that | |
1345 | the command resides there. This shortcut greatly speeds command location | |
1346 | when many directories are present in the search path. If this mechanism | |
1347 | has been turned off (via u\bun\bnh\bha\bas\bsh\bh), or if the shell was given a -\b-c\bc or -\b-t\bt | |
1348 | argument, and in any case for each directory component of _\bp_\ba_\bt_\bh that does | |
1349 | not begin with a `/', the shell concatenates with the given command name | |
1350 | to form a path name of a file which it then attempts to execute. | |
1351 | ||
1352 | Parenthesized commands are always executed in a subshell. Thus | |
1353 | ||
1354 | (cd; pwd); pwd | |
1355 | ||
1356 | prints the _\bh_\bo_\bm_\be directory; leaving you where you were (printing this af- | |
1357 | ter the home directory), while | |
1358 | ||
1359 | cd; pwd | |
1360 | ||
1361 | leaves you in the _\bh_\bo_\bm_\be directory. Parenthesized commands are most often | |
1362 | used to prevent c\bch\bhd\bdi\bir\br from affecting the current shell. | |
1363 | ||
1364 | If the file has execute permissions but is not an executable binary to | |
1365 | the system, then it is assumed to be a file containing shell commands and | |
1366 | a new shell is spawned to read it. | |
1367 | ||
1368 | If there is an a\bal\bli\bia\bas\bs for s\bsh\bhe\bel\bll\bl then the words of the alias will be | |
1369 | prepended to the argument list to form the shell command. The first word | |
1370 | of the a\bal\bli\bia\bas\bs should be the full path name of the shell (e.g., `$shell'). | |
1371 | Note that this is a special, late occurring, case of a\bal\bli\bia\bas\bs substitution, | |
1372 | and only allows words to be prepended to the argument list without | |
1373 | change. | |
1374 | ||
1375 | S\bSi\big\bgn\bna\bal\bl h\bha\ban\bnd\bdl\bli\bin\bng\bg | |
1376 | The shell normally ignores _\bq_\bu_\bi_\bt signals. Jobs running detached (either | |
1377 | by &\b& or the b\bbg\bg or %\b%.\b..\b..\b. &\b& commands) are immune to signals generated from | |
1378 | the keyboard, including hangups. Other signals have the values which the | |
1379 | shell inherited from its parent. The shell's handling of interrupts and | |
1380 | terminate signals in shell scripts can be controlled by o\bon\bni\bin\bnt\btr\br. Login | |
1381 | shells catch the _\bt_\be_\br_\bm_\bi_\bn_\ba_\bt_\be signal; otherwise this signal is passed on to | |
1382 | children from the state in the shell's parent. Interrupts are not al- | |
1383 | lowed when a login shell is reading the file _\b._\bl_\bo_\bg_\bo_\bu_\bt. | |
1384 | ||
1385 | A\bAU\bUT\bTH\bHO\bOR\bR | |
1386 | William Joy. Job control and directory stack features first implemented | |
1387 | by J.E. Kulp of IIASA, Laxenburg, Austria, with different syntax than | |
1388 | that used now. File name completion code written by Ken Greer, HP Labs. | |
1389 | Eight-bit implementation Christos S. Zoulas, Cornell University. | |
1390 | ||
1391 | F\bFI\bIL\bLE\bES\bS | |
1392 | ||
1393 | ||
1394 | ~/.cshrc Read at beginning of execution by each shell. | |
1395 | ~/.login Read by login shell, after `.cshrc' at login. | |
1396 | ~/.logout Read by login shell, at logout. | |
1397 | /bin/sh Standard shell, for shell scripts not starting with a `#'. | |
1398 | /tmp/sh* Temporary file for `<<'. | |
1399 | /etc/passwd Source of home directories for `~name'. | |
1400 | ||
1401 | L\bLI\bIM\bMI\bIT\bTA\bAT\bTI\bIO\bON\bNS\bS | |
1402 | Word lengths - Words can be no longer than 1024 characters. The system | |
1403 | limits argument lists to 10240 characters. The number of arguments to a | |
1404 | command that involves filename expansion is limited to 1/6'th the number | |
1405 | of characters allowed in an argument list. Command substitutions may | |
1406 | substitute no more characters than are allowed in an argument list. To | |
1407 | detect looping, the shell restricts the number of a\bal\bli\bia\bas\bs substitutions on | |
1408 | a single line to 20. | |
1409 | ||
1410 | S\bSE\bEE\bE A\bAL\bLS\bSO\bO | |
1411 | sh(1), access(2), execve(2), fork(2), killpg(2), pipe(2), | |
1412 | sigvec(2), umask(2), setrlimit(2), wait(2), tty(4), a.out(5), | |
1413 | environ(7), | |
1414 | introduction to the C shell | |
1415 | ||
1416 | H\bHI\bIS\bST\bTO\bOR\bRY\bY | |
1417 | C\bCs\bsh\bh appeared in 3BSD. It was a first implementation of a command language | |
1418 | interpreter incorporating a history mechanism (see _\bH_\bi_\bs_\bt_\bo_\br_\by | |
1419 | _\bS_\bu_\bb_\bs_\bt_\bi_\bt_\bu_\bt_\bi_\bo_\bn_\bs), job control facilities (see _\bJ_\bo_\bb_\bs), interactive file name | |
1420 | and user name completion (see _\bF_\bi_\bl_\be _\bN_\ba_\bm_\be _\bC_\bo_\bm_\bp_\bl_\be_\bt_\bi_\bo_\bn), and a C-like syntax. | |
1421 | There are now many shells that also have these mechanisms, plus a few | |
1422 | more (and maybe some bugs too), which are available through the usenet. | |
1423 | ||
1424 | B\bBU\bUG\bGS\bS | |
1425 | When a command is restarted from a stop, the shell prints the directory | |
1426 | it started in if this is different from the current directory; this can | |
1427 | be misleading (i.e., wrong) as the job may have changed directories in- | |
1428 | ternally. | |
1429 | ||
1430 | Shell builtin functions are not stoppable/restartable. Command sequences | |
1431 | of the form `a ; b ; c' are also not handled gracefully when stopping is | |
1432 | attempted. If you suspend `b', the shell will immediately execute `c'. | |
1433 | This is especially noticeable if this expansion results from an _\ba_\bl_\bi_\ba_\bs. It | |
1434 | suffices to place the sequence of commands in ()'s to force it to a sub- | |
1435 | shell, i.e., `( a ; b ; c )'. | |
1436 | ||
1437 | Control over tty output after processes are started is primitive; perhaps | |
1438 | this will inspire someone to work on a good virtual terminal interface. | |
1439 | In a virtual terminal interface much more interesting things could be | |
1440 | done with output control. | |
1441 | ||
1442 | Alias substitution is most often used to clumsily simulate shell proce- | |
1443 | dures; shell procedures should be provided instead of aliases. | |
1444 | ||
1445 | Commands within loops, prompted for by `?', are not placed on the h\bhi\bis\bst\bto\bor\bry\by | |
1446 | list. Control structure should be parsed instead of being recognized as | |
1447 | built-in commands. This would allow control commands to be placed any- | |
1448 | where, to be combined with `|', and to be used with `&' and `;' metasyn- | |
1449 | tax. | |
1450 | ||
1451 | It should be possible to use the `:' modifiers on the output of command | |
1452 | substitutions. | |
1453 | ||
1454 | The way the f\bfi\bil\ble\bec\bc facility is implemented is ugly and expensive. | |
1455 | ||
1456 | 4th Berkeley Distribution June 1, 1994 22 |