Commit | Line | Data |
---|---|---|
1d69d2db BJ |
1 | .if n .ds ua \o'^|' |
2 | .if t .ds ua \(ua | |
3 | .if n .ds aa ' | |
4 | .if t .ds aa \(aa | |
5 | .if n .ds ga ` | |
6 | .if t .ds ga \(ga | |
7 | .if t .tr *\(** | |
8 | .TH CSH UCB 2/24/79 UCB | |
9 | .SH NAME | |
10 | csh \- a shell (command interpreter) with C-like syntax | |
11 | .SH SYNOPSIS | |
12 | .B csh | |
13 | [ | |
14 | .B \-cef\^instvVxX | |
15 | ] [ | |
16 | arg ... | |
17 | ] | |
18 | .SH DESCRIPTION | |
19 | .I Csh | |
20 | is a command language interpreter. | |
21 | It begins by executing commands from the file `.cshrc' | |
22 | in the | |
23 | .I home | |
24 | directory of the invoker. | |
25 | If this is a login shell then it also executes commands from the file | |
26 | `.login' there. | |
27 | In the normal case, the shell will then begin reading commands from the | |
28 | terminal, prompting with `% '. | |
29 | Processing of arguments and the use of the shell to process files | |
30 | containing command scripts will be described later. | |
31 | .PP | |
32 | The shell then repeatedly performs the following actions: | |
33 | a line of command input is read and broken into | |
34 | .I words. | |
35 | This sequence of words is placed on the command history list and then parsed. | |
36 | Finally each command in the current line is executed. | |
37 | .PP | |
38 | When a login shell terminates it executes commands from the file `.logout' | |
39 | in the users home directory. | |
40 | .PP | |
41 | .B "Lexical structure" | |
42 | .PP | |
43 | The shell splits input lines into words at blanks and tabs with the | |
44 | following exceptions. | |
45 | The characters | |
46 | `&' `|' `;' `<' `>' `(' `)' | |
47 | form separate words. | |
48 | If doubled in `&&', `|\|\||', `<<' or `>>' these pairs form single words. | |
49 | These parser metacharacters may be made part of other words, or prevented their | |
50 | special meaning, by preceding them with `\e'. | |
51 | A newline preceded by a `\e' is equivalent to a blank. | |
52 | .PP | |
53 | In addition strings enclosed in matched pairs of quotations, | |
54 | `\*(aa', `\*(ga' or `"', | |
55 | form parts of a word; metacharacters in these strings, including blanks | |
56 | and tabs, do not form separate words. | |
57 | These quotations have semantics to be described subsequently. | |
58 | Within pairs of `\' or `"' characters a newline preceded by a `\e' gives | |
59 | a true newline character. | |
60 | .PP | |
61 | When the shell's input is not a terminal, | |
62 | the character `#' introduces a comment which continues to the end of the | |
63 | input line. | |
64 | It is prevented this special meaning when preceded by `\e' | |
65 | and in quotations using `\`', `\'', and `"'. | |
66 | .PP | |
67 | .B Commands | |
68 | .PP | |
69 | A simple command is a sequence of words, the first of which | |
70 | specifies the command to be executed. | |
71 | A simple command or | |
72 | a sequence of simple commands separated by `|' characters | |
73 | forms a pipeline. | |
74 | The output of each command in a pipeline is connected to the input of the next. | |
75 | Sequences of pipelines may be separated by `;', and are then executed | |
76 | sequentially. | |
77 | A sequence of pipelines may be executed without waiting for it to terminate | |
78 | by following it with an `&'. | |
79 | .PP | |
80 | Any of the above may be placed in `(' `)' to form a simple command (which | |
81 | may be a component of a pipeline, etc.) | |
82 | It is also possible to separate pipelines with `|\|\||' or `&&' indicating, | |
83 | as in the C language, | |
84 | that the second is to be executed only if the first fails or succeeds | |
85 | respectively. (See | |
86 | .I Expressions.) | |
87 | .PP | |
88 | .B Substitutions | |
89 | .PP | |
90 | We now describe the various transformations the shell performs on the | |
91 | input in the order in which they occur. | |
92 | .PP | |
93 | .B "History substitutions" | |
94 | .PP | |
95 | History substitutions can be used to reintroduce sequences of words | |
96 | from previous commands, possibly performing modifications on these words. | |
97 | Thus history substitutions provide a generalization of a | |
98 | .I redo | |
99 | function. | |
100 | .PP | |
101 | History substitutions begin with the character `!' and may begin | |
102 | .B anywhere | |
103 | in the input stream if a history substitution is not already in progress. | |
104 | This `!' may be preceded by an `\e' to prevent its special meaning; | |
105 | a `!' is passed unchanged when it is followed by a blank, | |
106 | tab, newline, `=' or `('. | |
107 | History substitutions also occur when an input line begins with `\*(ua'. | |
108 | This special abbreviation will be described later. | |
109 | .PP | |
110 | Any input line which contains history substitution is echoed on the terminal | |
111 | before it is executed as it could have been typed without history substitution. | |
112 | .PP | |
113 | Commands input from the terminal which consist of one or more words | |
114 | are saved on the history list, | |
115 | the size of which is controlled by the | |
116 | .I history | |
117 | variable. | |
118 | The previous command is always retained. | |
119 | Commands are numbered sequentially from 1. | |
120 | .PP | |
121 | For definiteness, consider the following output from the history command: | |
122 | .PP | |
123 | .DT | |
124 | .br | |
125 | \09 write michael | |
126 | .br | |
127 | 10 ex write.c | |
128 | .br | |
129 | 11 cat oldwrite.c | |
130 | .br | |
131 | 12 diff *write.c | |
132 | .PP | |
133 | The commands are shown with their event numbers. | |
134 | It is not usually necessary to use event numbers, but the current event | |
135 | number can be made part of the | |
136 | .I prompt | |
137 | by placing an `!' in the prompt string. | |
138 | .PP | |
139 | With the current event 13 we can refer to previous events by event | |
140 | number `!11', relatively as in `!\-2' (referring to the same event), | |
141 | by a prefix of a command word | |
142 | as in `!d' for event 12 or `!w' for event 9, or by a string contained in | |
143 | a word in the command as in `!?mic?' also referring to event 9. | |
144 | These forms, without further modification, simply reintroduce the words | |
145 | of the specified events, each separated by a single blank. | |
146 | As a special case `!!' refers to the previous command; thus `!!' | |
147 | alone is essentially a | |
148 | .I redo. | |
149 | .PP | |
150 | To select words from an event we can follow the event specification by | |
151 | a `:' and a designator for the desired words. | |
152 | The words of a input line are numbered from 0, | |
153 | the first (usually command) word being 0, the second word (first argument) | |
154 | being 1, etc. | |
155 | The basic word designators are: | |
156 | .PP | |
157 | .DT | |
158 | .nf | |
159 | 0 first (command) word | |
160 | \fIn\fR \fIn\fR\|'th argument | |
161 | \*(ua first argument, i.e. `1' | |
162 | $ last argument | |
163 | % word matched by (immediately preceding) ?\fIs\fR\|? search | |
164 | \fIx\fR\|\-\fIy\fR range of words | |
165 | \-\fIy\fR abbreviates `0\-\fIy\fR\|' | |
166 | * abbreviates `\*(ua\-$', or nothing if only 1 word in event | |
167 | \fIx\fR\|* abbreviates `\fIx\fR\|\-$' | |
168 | \fIx\fR\|\- like `\fIx\fR\|*' but omitting word `$' | |
169 | .fi | |
170 | .PP | |
171 | The `:' separating the event specification from the word designator | |
172 | can be omitted if the argument selector begins with a `\*(ua', `$', `*' | |
173 | `\-' or `%'. | |
174 | After the optional word designator can be | |
175 | placed a sequence of modifiers, each preceded by a `:'. | |
176 | The following modifiers are defined: | |
177 | .DT | |
178 | .PP | |
179 | .nf | |
180 | h Remove a trailing pathname component, leaving the head. | |
181 | r Remove a trailing `.xxx' component, leaving the root name. | |
182 | s/\fIl\fR\|/\fIr\fR\|/ Substitute \fIr\fR for \fIr\fR | |
183 | t Remove all leading pathname components, leaving the tail. | |
184 | & Repeat the previous substitution. | |
185 | g Apply the change globally, prefixing the above, e.g. `g&'. | |
186 | p Print the new command but do not execute it. | |
187 | q Quote the substituted words, preventing further substitutions. | |
188 | x Like q, but break into words at blanks, tabs and newlines. | |
189 | .fi | |
190 | .PP | |
191 | Unless preceded by a `g' the modification is applied only to the first | |
192 | modifiable word. In any case it is an error for no word to be applicable. | |
193 | .PP | |
194 | The left hand side of substitutions are not regular expressions in the sense | |
195 | of the editors, but rather strings. | |
196 | Any character may be used as the delimiter in place of `/'; | |
197 | a `\e' quotes the delimiter into the | |
198 | .IR l "" | |
199 | and | |
200 | .IR r "" | |
201 | strings. | |
202 | The character `&' in the right hand side is replaced by the text from | |
203 | the left. | |
204 | A `\e' quotes `&' also. | |
205 | A null | |
206 | .IR l "" | |
207 | uses the previous string either from a | |
208 | .IR l "" | |
209 | or from a | |
210 | contextual scan string | |
211 | .IR s "" | |
212 | in `!?\fIs\fR\|?'. | |
213 | The trailing delimiter in the substitution may be omitted if a newline | |
214 | follows immediately as may the trailing `?' in a contextual scan. | |
215 | .PP | |
216 | A history reference may be given without an event specification, e.g. `!$'. | |
217 | In this case the reference is to the previous command unless a previous | |
218 | history reference occurred on the same line in which case this form repeats | |
219 | the previous reference. | |
220 | Thus `!?foo?\*(ua !$' gives the first and last arguments | |
221 | from the command matching `?foo?'. | |
222 | .PP | |
223 | A special abbreviation of a history reference occurs when the first | |
224 | non-blank character of an input line is a `\*(ua'. | |
225 | This is equivalent to `!:s\*(ua' providing a convenient shorthand for substitutions | |
226 | on the text of the previous line. | |
227 | Thus `\*(ualb\*(ualib' fixes the spelling of | |
228 | `lib' | |
229 | in the previous command. | |
230 | Finally, a history substitution may be surrounded with `{' and `}' | |
231 | if necessary to insulate it from the characters which follow. | |
232 | Thus, after `ls \-ld ~paul' we might do `!{l}a' to do `ls \-ld ~paula', | |
233 | while `!la' would look for a command starting `la'. | |
234 | .PP | |
235 | .if n .ul | |
236 | \fBQuotations\ with\ \'\ and\ "\fR | |
237 | .PP | |
238 | The quotation of strings by `\'' and `"' can be used | |
239 | to prevent all or some of the remaining substitutions. | |
240 | Strings enclosed in `\'' are prevented any further interpretation. | |
241 | Strings enclosed in `"' are yet variable and command expanded | |
242 | as described below. | |
243 | .PP | |
244 | In both cases the resulting text becomes (all or part of) a single word; | |
245 | only in one special case (see | |
246 | .I "Command Substitition" | |
247 | below) does a `"' quoted string yield parts of more than one word; | |
248 | `\' quoted strings never do. | |
249 | .PP | |
250 | .B "Alias substitution" | |
251 | .PP | |
252 | The shell maintains a list of aliases which can be established, displayed | |
253 | and modified by the | |
254 | .I alias | |
255 | and | |
256 | .I unalias | |
257 | commands. | |
258 | After a command line is scanned, it is parsed into distinct commands and | |
259 | the first word of each command, left-to-right, is checked to see if it | |
260 | has an alias. | |
261 | If it does, then the text which is the alias for that command is reread | |
262 | with the history mechanism available | |
263 | as though that command were the previous input line. | |
264 | The resulting words replace the | |
265 | command and argument list. | |
266 | If no reference is made to the history list, then the argument list is | |
267 | left unchanged. | |
268 | .PP | |
269 | Thus if the alias for `ls' is `ls \-l' the command `ls /usr' would map to | |
270 | `ls \-l /usr', the argument list here being undisturbed. | |
271 | Similarly if the alias for `lookup' was `grep !\*(ua /etc/passwd' then | |
272 | `lookup bill' would map to `grep bill /etc/passwd'. | |
273 | .PP | |
274 | If an alias is found, the word transformation of the input text | |
275 | is performed and the aliasing process begins again on the reformed input line. | |
276 | Looping is prevented if the first word of the new text is the same as the old | |
277 | by flagging it to prevent further aliasing. | |
278 | Other loops are detected and cause an error. | |
279 | .PP | |
280 | Note that the mechanism allows aliases to introduce parser metasyntax. | |
281 | Thus we can `alias print \'pr \e!* \||\| lpr\'' to make a command which | |
282 | .I pr's | |
283 | its arguments to the line printer. | |
284 | .PP | |
285 | .B "Variable substitution" | |
286 | .PP | |
287 | The shell maintains a set of variables, each of which has as value a list | |
288 | of zero or more words. | |
289 | Some of these variables are set by the shell or referred to by it. | |
290 | For instance, the | |
291 | .I argv | |
292 | variable is an image of the shell's argument list, and words of this | |
293 | variable's value are referred to in special ways. | |
294 | .PP | |
295 | The values of variables may be displayed and changed by using the | |
296 | .I set | |
297 | and | |
298 | .I unset | |
299 | commands. | |
300 | Of the variables referred to by the shell a number are toggles; | |
301 | the shell does not care what their value is, | |
302 | only whether they are set or not. | |
303 | For instance, the | |
304 | .I verbose | |
305 | variable is a toggle which causes command input to be echoed. | |
306 | The setting of this variable results from the | |
307 | .B \-v | |
308 | command line option. | |
309 | .PP | |
310 | Other operations treat variables numerically. | |
311 | The `@' command permits numeric calculations to be performed and the result | |
312 | assigned to a variable. | |
313 | Variable values are, however, always represented as (zero or more) strings. | |
314 | For the purposes of numeric operations, the null string is considered to be | |
315 | zero, and the second and subsequent words of multiword values are ignored. | |
316 | .PP | |
317 | After the input line is aliased and parsed, and before each command | |
318 | is executed, variable substitution | |
319 | is performed keyed by `$' characters. | |
320 | This expansion can be prevented by preceding the `$' with a `\e' except | |
321 | within `"'s where it | |
322 | .B always | |
323 | occurs, and within `\'s where it | |
324 | .B never | |
325 | occurs. | |
326 | Strings quoted by `\*(ga' are interpreted later (see | |
327 | .I "Command substitution" | |
328 | below) so `$' substitution does not occur there until later, if at all. | |
329 | A `$' is passed unchanged if followed by a blank, tab, or end-of-line. | |
330 | .PP | |
331 | Input/output redirections are recognized before variable expansion, | |
332 | and are variable expanded separately. | |
333 | Otherwise, the command name and entire argument list are expanded together. | |
334 | It is thus possible for the first (command) word to this point to generate | |
335 | more than one word, the first of which becomes the command name, | |
336 | and the rest of which become arguments. | |
337 | .PP | |
338 | Unless enclosed in `"' or given the `:q' modifier the results of variable | |
339 | substitution may eventually be command and filename substituted. | |
340 | Within `"' a variable whose value consists of multiple words expands to a | |
341 | (portion of) a single word, with the words of the variables value | |
342 | separated by blanks. | |
343 | When the `:q' modifier is applied to a substitution | |
344 | the variable will expand to multiple words with each word separated | |
345 | by a blank and quoted to prevent later command or filename substitution. | |
346 | .PP | |
347 | The following metasequences are provided for introducing variable values into | |
348 | the shell input. | |
349 | Except as noted, it is an error to reference a variable which is not set. | |
350 | .HP 5 | |
351 | $name | |
352 | .br | |
353 | .ns | |
354 | .HP 5 | |
355 | ${name} | |
356 | .br | |
357 | Are replaced by the words of the value of variable | |
358 | .I name, | |
359 | each separated by a blank. | |
360 | Braces insulate | |
361 | .I name | |
362 | from following characters which would otherwise be part of it. | |
363 | Shell variables have names consisting of up to 20 letters | |
364 | and underscores. | |
365 | .HP 5 | |
366 | $name[selector] | |
367 | .br | |
368 | .ns | |
369 | .HP 5 | |
370 | ${name[selector]} | |
371 | .br | |
372 | May be used to select only some of the words from the value of | |
373 | .I name. | |
374 | The selector is subjected to `$' substitution and may consist of a single | |
375 | number or two numbers separated by a `\-'. | |
376 | The first word of a variables value is numbered `1'. | |
377 | If the first number of a range is omitted it defaults to `1'. | |
378 | If the last member of a range is omitted it defaults to `$#name'. | |
379 | The selector `*' selects all words. | |
380 | It is not an error for a range to be empty if the second argument is omitted | |
381 | or in range. | |
382 | .HP 5 | |
383 | $#name | |
384 | .br | |
385 | .ns | |
386 | .HP 5 | |
387 | ${#name} | |
388 | .br | |
389 | Gives the number of words in the variable. | |
390 | This is useful for later use in a `[selector]'. | |
391 | .HP 5 | |
392 | $0 | |
393 | .br | |
394 | Substitutes the name of the file from which command input is being read. | |
395 | An error occurs if the name is not known. | |
396 | .HP 5 | |
397 | $number | |
398 | .br | |
399 | .ns | |
400 | .HP 5 | |
401 | ${number} | |
402 | .br | |
403 | Equivalent to `$argv[number]'. | |
404 | .HP 5 | |
405 | $* | |
406 | .br | |
407 | Equivalent to `$argv[*]'. | |
408 | .PP | |
409 | The modifiers `:h', `:t', `:r', `:q' and `:x' may be applied to | |
410 | the substitutions above as may `:gh', `:gt' and `:gr'. | |
411 | If braces `{' '}' appear in the command form then the modifiers | |
412 | must appear within the braces. | |
413 | .B "The current implementation allows only one `:' modifier on each `$' expansion." | |
414 | .PP | |
415 | The following substitutions may not be modified with `:' modifiers. | |
416 | .HP 5 | |
417 | $?name | |
418 | .br | |
419 | .ns | |
420 | .HP 5 | |
421 | ${?name} | |
422 | .br | |
423 | Substitutes the string `1' if name is set, `0' if it is not. | |
424 | .HP 5 | |
425 | $?0 | |
426 | .br | |
427 | Substitutes `1' if the current input filename is know, `0' if it is not. | |
428 | .HP 5 | |
429 | $$ | |
430 | .br | |
431 | Substitute the (decimal) process number of the (parent) shell. | |
432 | .PP | |
433 | .B "Command and filename substitution" | |
434 | .PP | |
435 | The remaining substitutions, command and filename substitution, | |
436 | are applied selectively to the arguments of builtin commands. | |
437 | This means that portions of expressions which are not evaluated are | |
438 | not subjected to these expansions. | |
439 | For commands which are not internal to the shell, the command | |
440 | name is substituted separately from the argument list. | |
441 | This occurs very late, | |
442 | after input-output redirection is performed, and in a child | |
443 | of the main shell. | |
444 | .PP | |
445 | .B "Command substitution" | |
446 | .PP | |
447 | Command substitution is indicated by a command enclosed in `\*(ga'. | |
448 | The output from such a command is normally broken into separate words | |
449 | at blanks, tabs and newlines, with null words being discarded, | |
450 | this text then replacing the original string. | |
451 | Within `"'s, only newlines force new words; blanks and tabs are preserved. | |
452 | .PP | |
453 | In any case, the single final newline does not force a new word. | |
454 | Note that it is thus possible for a command substitution to yield | |
455 | only part of a word, even if the command outputs a complete line. | |
456 | .PP | |
457 | .B "Filename substitution" | |
458 | .PP | |
459 | If a word contains any of the characters `*', `?', `[' or `{' | |
460 | or begins with the character `~', then that word is a candidate for | |
461 | filename substitution, also known as `globbing'. | |
462 | This word is then regarded as a pattern, and replaced with an alphabetically | |
463 | sorted list of file names which match the pattern. | |
464 | In a list of words specifying filename substitution it is an error for | |
465 | no pattern to match an existing file name, but it is not required | |
466 | for each pattern to match. | |
467 | Only the metacharacters `*', `?' and `[' imply pattern matching, | |
468 | the characters `~' and `{' being more akin to abbreviations. | |
469 | .PP | |
470 | In matching filenames, the character `.' at the beginning of a filename | |
471 | or immediately following a `/', as well as the character `/' must | |
472 | be matched explicitly. | |
473 | The character `*' matches any string of characters, including the null | |
474 | string. | |
475 | The character `?' matches any single character. | |
476 | The sequence `[...]' matches any one of the characters enclosed. | |
477 | Within `[...]', | |
478 | a pair of characters separated by `\-' matches any character lexically between | |
479 | the two. | |
480 | .PP | |
481 | The character `~' at the beginning of a filename is used to refer to home | |
482 | directories. | |
483 | Standing alone, i.e. `~' it expands to the invokers home directory as reflected | |
484 | in the value of the variable | |
485 | .I home. | |
486 | When followed by a name consisting of letters, digits and `\-' characters | |
487 | the shell searches for a user with that name and substitutes their | |
488 | home directory; thus `~ken' might expand to `/usr/ken' and `~ken/chmach' | |
489 | to `/usr/ken/chmach'. | |
490 | If the character `~' is followed by a character other than a letter or `/' | |
491 | or appears not at the beginning of a word, | |
492 | it is left undisturbed. | |
493 | .PP | |
494 | The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'. | |
495 | Left to right order is preserved, with results of matches being sorted | |
496 | separately at a low level to preserve this order. | |
497 | This construct may be nested. | |
498 | Thus `~source/s1/{oldls,ls}.c' expands to | |
499 | `/usr/source/s1/oldls.c /usr/source/s1/ls.c' | |
500 | whether or not these files exist without any chance of error | |
501 | if the home directory for `source' is `/usr/source'. | |
502 | Similarly `../{memo,*box}' might expand to `../memo ../box ../mbox'. | |
503 | (Note that `memo' was not sorted with the results of matching `*box'.) | |
504 | As a special case `{', `}' and `{}' are passed undisturbed. | |
505 | .PP | |
506 | .B Input/output | |
507 | .PP | |
508 | The standard input and standard output of a command may be redirected | |
509 | with the following syntax: | |
510 | .HP 5 | |
511 | < name | |
512 | .br | |
513 | Open file | |
514 | .I name | |
515 | (which is first variable, command and filename expanded) as the standard | |
516 | input. | |
517 | .HP 5 | |
518 | << word | |
519 | .br | |
520 | Read the shell input up to a line which is identical to | |
521 | .I word. | |
522 | .I Word | |
523 | is not subjected to variable, filename or command substitution, | |
524 | and each input line is compared to | |
525 | .I word | |
526 | before any substitutions are done on this input line. | |
527 | Unless a quoting `\e', `"', `\*(aa' or `\*(ga' appears in | |
528 | .I word | |
529 | variable and command substitution is performed on the intervening lines, | |
530 | allowing `\e' to quote `$', `\e' and `\*(ga'. | |
531 | Commands which are substituted have all blanks, tabs, and newlines | |
532 | preserved, except for the final newline which is dropped. | |
533 | The resultant text is placed in an anonymous temporary file which | |
534 | is given to the command as standard input. | |
535 | .HP 5 | |
536 | > name | |
537 | .br | |
538 | .ns | |
539 | .HP 5 | |
540 | >! name | |
541 | .br | |
542 | .ns | |
543 | .HP 5 | |
544 | >& name | |
545 | .br | |
546 | .ns | |
547 | .HP 5 | |
548 | >&! name | |
549 | .br | |
550 | The file | |
551 | .I name | |
552 | is used as standard output. | |
553 | If the file does not exist then it is created; | |
554 | if the file exists, its is truncated, its previous contents being lost. | |
555 | .IP | |
556 | If the variable | |
557 | .I noclobber | |
558 | is set, then the file must not exist or be a character special file (e.g. a | |
559 | terminal or `/dev/null') or an error results. | |
560 | This helps prevent accidental destruction of files. | |
561 | In this case the `!' forms can be used and suppress this check. | |
562 | .IP | |
563 | The forms involving `&' route the diagnostic output into the specified | |
564 | file as well as the standard output. | |
565 | .I Name | |
566 | is expanded in the same way as `<' input filenames are. | |
567 | .HP 5 | |
568 | >> name | |
569 | .br | |
570 | .ns | |
571 | .HP 5 | |
572 | >>& name | |
573 | .br | |
574 | .ns | |
575 | .HP 5 | |
576 | >>! name | |
577 | .br | |
578 | .ns | |
579 | .HP 5 | |
580 | >>&! name | |
581 | .br | |
582 | Uses file | |
583 | .I name | |
584 | as standard output like `>' but places output at the end of the file. | |
585 | If the variable | |
586 | .I noclobber | |
587 | is set, then | |
588 | it is an error for the file not to exist unless | |
589 | one of the `!' forms is given. | |
590 | Otherwise similar to `>'. | |
591 | .PP | |
592 | If a command is run detached (followed by `&') then the default standard | |
593 | input for the command is the empty file `/dev/null'. | |
594 | Otherwise the command receives the environment in which the shell was | |
595 | invoked as modified by the input-output parameters and | |
596 | the presence of the command in a pipeline. | |
597 | Thus, unlike some previous shells, commands run from a file of shell commands | |
598 | have no access to the text of the commands by default; rather | |
599 | they receive the original standard input of the shell. | |
600 | The `<<' mechanism should be used to present inline data. | |
601 | This permits shell command scripts to function as components of pipelines | |
602 | and allows the shell to block read its input. | |
603 | .PP | |
604 | Diagnostic output may be directed through a pipe with the standard output. | |
605 | Simply use the form `|\|&' rather than just `|'. | |
606 | .PP | |
607 | .B Expressions | |
608 | .PP | |
609 | A number of the builtin commands (to be described subsequently) | |
610 | take expressions, in which the operators are similar to those of C, with | |
611 | the same precedence. | |
612 | These expressions appear in the | |
613 | .I @, | |
614 | .I exit, | |
615 | .I if, | |
616 | and | |
617 | .I while | |
618 | commands. | |
619 | The following operators are available: | |
620 | .DT | |
621 | .PP | |
622 | |\|\|| && | \*(ua & == != <= >= < > << >> + \- * / % ! ~ ( ) | |
623 | .PP | |
624 | Here the precedence increases to the right, | |
625 | `==' and `!=', `<=' `>=' `<' and `>', `<<' and `>>', `+' and `\-', | |
626 | `*' `/' and `%' being, in groups, at the same level. | |
627 | The `==' and `!=' operators compare their arguments as strings, | |
628 | all others operate on numbers. | |
629 | Strings which begin with `0' are considered octal numbers. | |
630 | Null or missing arguments are considered `0'. | |
631 | The result of all expressions are strings, | |
632 | which represent decimal numbers. | |
633 | It is important to note that no two components of an expression can appear | |
634 | in the same word; except when adjacent to components of expressions which | |
635 | are syntactically significant to the parser (`&' `|' `<' `>' `(' `)') | |
636 | they should be surrounded by spaces. | |
637 | .PP | |
638 | Also available in expressions as primitive operands are command executions | |
639 | enclosed in `{' and `}' | |
640 | and file enquiries of the form `\-\fIl\fR name' where | |
641 | .I l | |
642 | is one of: | |
643 | .PP | |
644 | .DT | |
645 | .nf | |
646 | r read access | |
647 | w write access | |
648 | x execute access | |
649 | e existence | |
650 | o ownership | |
651 | z zero size | |
652 | f plain file | |
653 | d directory | |
654 | .fi | |
655 | .PP | |
656 | The specified name is command and filename expanded and then tested | |
657 | to see if it has the specified relationship to the real user. | |
658 | If the file does not exist or is inaccessible then all enquiries return | |
659 | false, i.e. `0'. | |
660 | Command executions succeed, returning true, i.e. `1', | |
661 | if the command exits with status 0, otherwise they fail, returning | |
662 | false, i.e. `0'. | |
663 | If more detailed status information is required then the command | |
664 | should be executed outside of an expression and the variable | |
665 | .I status | |
666 | examined. | |
667 | .PP | |
668 | .B "Control flow" | |
669 | .PP | |
670 | The shell contains a number of commands which can be used to regulate the | |
671 | flow of control in command files (shell scripts) and | |
672 | (in limited but useful ways) from terminal input. | |
673 | These commands all operate by forcing the shell to reread or skip in its | |
674 | input and, due to the implementation, restrict the placement of some | |
675 | of the commands. | |
676 | .PP | |
677 | The | |
678 | .I foreach, | |
679 | .I switch, | |
680 | and | |
681 | .I while | |
682 | statements, as well as the | |
683 | .I if\-then\-else | |
684 | form of the | |
685 | .I if | |
686 | statement require that the major keywords appear in a single simple command | |
687 | on an input line as shown below. | |
688 | .PP | |
689 | If the shell's input is not seekable, | |
690 | the shell buffers up input whenever a loop is being read | |
691 | and performs seeks in this internal buffer to accomplish the rereading | |
692 | implied by the loop. | |
693 | (To the extent that this allows, backward goto's will succeed on | |
694 | non-seekable inputs.) | |
695 | .PP | |
696 | .B "Builtin commands" | |
697 | .PP | |
698 | Builtin commands are executed within the shell. | |
699 | If a builtin command occurs as any component of a pipeline | |
700 | except the last then it is executed in a subshell. | |
701 | .HP 5 | |
702 | .B alias | |
703 | .br | |
704 | .ns | |
705 | .HP 5 | |
706 | .BR alias " name" | |
707 | .br | |
708 | .ns | |
709 | .HP 5 | |
710 | .BR alias " name wordlist" | |
711 | .br | |
712 | The first form prints all aliases. | |
713 | The second form prints the alias for name. | |
714 | The final form assigns the specified | |
715 | .I wordlist | |
716 | as the alias of | |
717 | .I name; | |
718 | .I wordlist | |
719 | is command and filename substituted. | |
720 | .I Name | |
721 | is not allowed to be | |
722 | .I alias | |
723 | or | |
724 | .I unalias | |
725 | .HP 5 | |
726 | .B alloc | |
727 | .br | |
728 | Shows the amount of dynamic core in use, broken down into used and | |
729 | free core, and address of the last location in the heap. | |
730 | With an argument shows each used and free block on the internal dynamic | |
731 | memory chain indicating its address, size, and whether it is used or free. | |
732 | This is a debugging command and may not work in production versions of the | |
733 | shell; it requires a modified version of the system memory allocator. | |
734 | .HP 5 | |
735 | .B break | |
736 | .br | |
737 | Causes execution to resume after the | |
738 | .I end | |
739 | of the nearest enclosing | |
740 | .I forall | |
741 | or | |
742 | .I while. | |
743 | The remaining commands on the current line are executed. | |
744 | Multi-level breaks are thus possible by writing them all on one line. | |
745 | .HP 5 | |
746 | .B breaksw | |
747 | .br | |
748 | Causes a break from a | |
749 | .I switch, | |
750 | resuming after the | |
751 | .I endsw. | |
752 | .HP 5 | |
753 | .BR case " label:" | |
754 | .br | |
755 | A label in a | |
756 | .I switch | |
757 | statement as discussed below. | |
758 | .HP 5 | |
759 | .B cd | |
760 | .br | |
761 | .ns | |
762 | .HP 5 | |
763 | .BR cd " name" | |
764 | .br | |
765 | .ns | |
766 | .HP 5 | |
767 | .B chdir | |
768 | .br | |
769 | .ns | |
770 | .HP 5 | |
771 | .BR chdir " name" | |
772 | .br | |
773 | Change the shells working directory to directory | |
774 | .I name. | |
775 | If no argument is given then change to the home directory of the user. | |
776 | .HP 5 | |
777 | .B continue | |
778 | .br | |
779 | Continue execution of the nearest enclosing | |
780 | .I while | |
781 | or | |
782 | .I foreach. | |
783 | The rest of the commands on the current line are executed. | |
784 | .HP 5 | |
785 | .B default: | |
786 | .br | |
787 | Labels the default case in a | |
788 | .I switch | |
789 | statement. | |
790 | The default should come after all | |
791 | .I case | |
792 | labels. | |
793 | .HP 5 | |
794 | .BR echo " wordlist" | |
795 | .br | |
796 | The specified words are written to the shells standard output. | |
797 | A `\ec' causes the echo to complete without printing a newline, | |
798 | akin to the `\ec' in | |
799 | .IR nroff (1). | |
800 | A `\en' in wordlist causes a newline to be printed. | |
801 | Otherwise the words are echoed, separated by spaces. | |
802 | .HP 5 | |
803 | .B else | |
804 | .br | |
805 | .ns | |
806 | .HP 5 | |
807 | .B end | |
808 | .br | |
809 | .ns | |
810 | .HP 5 | |
811 | .B endif | |
812 | .br | |
813 | .ns | |
814 | .HP 5 | |
815 | .B endsw | |
816 | .br | |
817 | See the description of the | |
818 | .I foreach, | |
819 | .I if, | |
820 | .I switch, | |
821 | and | |
822 | .I while | |
823 | statements below. | |
824 | .HP 5 | |
825 | .BR exec " command" | |
826 | .br | |
827 | The specified command is executed in place of the current shell. | |
828 | .HP 5 | |
829 | .B exit | |
830 | .br | |
831 | .ns | |
832 | .HP 5 | |
833 | .BR exit (expr) | |
834 | .br | |
835 | The shell exits either with the value of the | |
836 | .I status | |
837 | variable (first form) or with the value of the specified | |
838 | .I expr | |
839 | (second form). | |
840 | .HP 5 | |
841 | .BR foreach " name (wordlist)" | |
842 | .br | |
843 | .ns | |
844 | .HP 5 | |
845 | \ ... | |
846 | .br | |
847 | .ns | |
848 | .HP 5 | |
849 | .B end | |
850 | .br | |
851 | The variable | |
852 | .I name | |
853 | is successively set to each member of | |
854 | .I wordlist | |
855 | and the sequence of commands between this command and the matching | |
856 | .I end | |
857 | are executed. | |
858 | (Both | |
859 | .I foreach | |
860 | and | |
861 | .I end | |
862 | must appear alone on separate lines.) | |
863 | .IP | |
864 | The builtin command | |
865 | .I continue | |
866 | may be used to continue the loop prematurely and the builtin | |
867 | command | |
868 | .I break | |
869 | to terminate it prematurely. | |
870 | When this command is read from the terminal, the loop is read up once | |
871 | prompting with `?' before any statements in the loop are executed. | |
872 | If you make a mistake typing in a loop at the terminal you can rub it out. | |
873 | .HP 5 | |
874 | .BR glob " wordlist" | |
875 | .br | |
876 | Like | |
877 | .I echo | |
878 | but no `\e' escapes are recognized and words are delimited | |
879 | by null characters in the output. | |
880 | Useful for programs which wish to use the shell to filename expand a list | |
881 | of words. | |
882 | .HP 5 | |
883 | .BR goto " word" | |
884 | .br | |
885 | The specified | |
886 | .I word | |
887 | is filename and command expanded to yield a string of the form `label'. | |
888 | The shell rewinds its input as much as possible | |
889 | and searches for a line of the form `label:' | |
890 | possibly preceded by blanks or tabs. | |
891 | Execution continues after the specified line. | |
892 | .HP 5 | |
893 | .B history | |
894 | .br | |
895 | Displays the history event list. | |
896 | .HP 5 | |
897 | .BR if " (expr) command" | |
898 | .br | |
899 | If the specified expression evaluates true, then the single | |
900 | .I command | |
901 | with arguments is executed. | |
902 | Variable substitution on | |
903 | .IR command "" | |
904 | happens early, at the same | |
905 | time it does for the rest of the | |
906 | .I if | |
907 | command. | |
908 | .I Command | |
909 | must be a simple command, not | |
910 | a pipeline, a command list, or a parenthesized command list. | |
911 | Input/output redirection occurs even if | |
912 | .I expr | |
913 | is false, when command is | |
914 | .B not | |
915 | executed (this is a bug). | |
916 | .HP 5 | |
917 | .BR if " (expr) " "then" | |
918 | .br | |
919 | .ns | |
920 | .HP 5 | |
921 | \ ... | |
922 | .br | |
923 | .ns | |
924 | .HP 5 | |
925 | .BR else " " "if\fR (expr2) \fBthen" | |
926 | .br | |
927 | .ns | |
928 | .HP 5 | |
929 | \ ... | |
930 | .br | |
931 | .ns | |
932 | .HP 5 | |
933 | .B else | |
934 | .br | |
935 | .ns | |
936 | .HP 5 | |
937 | \ ... | |
938 | .br | |
939 | .ns | |
940 | .HP 5 | |
941 | .B endif | |
942 | .br | |
943 | If the specified | |
944 | .IR expr "" | |
945 | is true then the commands to the first | |
946 | .I else | |
947 | are executed; else if | |
948 | .IR expr2 "" | |
949 | is true then the commands to the | |
950 | second else are executed, etc. | |
951 | Any number of | |
952 | .I else-if | |
953 | pairs are possible; only one | |
954 | .I endif | |
955 | is needed. | |
956 | The | |
957 | .I else | |
958 | part is likewise optional. | |
959 | (The words | |
960 | .I else | |
961 | and | |
962 | .I endif | |
963 | must appear at the beginning of input lines; | |
964 | the | |
965 | .I if | |
966 | must appear alone on its input line or after an | |
967 | .I else.) | |
968 | .HP 5 | |
969 | .B logout | |
970 | .br | |
971 | Terminate a login shell. | |
972 | Especially useful if | |
973 | .I ignoreeof | |
974 | is set. | |
975 | .HP 5 | |
976 | .B nice | |
977 | .br | |
978 | .ns | |
979 | .HP 5 | |
980 | .BR nice " \+number" | |
981 | .br | |
982 | .ns | |
983 | .HP 5 | |
984 | .BR nice " command" | |
985 | .br | |
986 | .ns | |
987 | .HP 5 | |
988 | .BR nice " \+number command" | |
989 | .br | |
990 | The first form sets the | |
991 | .I nice | |
992 | for this shell to 4. | |
993 | The second form sets the | |
994 | .I nice | |
995 | to the given number. | |
996 | The final two forms run command at priority 4 and | |
997 | .I number | |
998 | respectively. | |
999 | The super-user may specify negative niceness by using `nice \-number ...'. | |
1000 | Command is always executed in a sub-shell, and the restrictions | |
1001 | place on commands in simple | |
1002 | .I if | |
1003 | statements apply. | |
1004 | .HP 5 | |
1005 | .B nohup | |
1006 | .br | |
1007 | .ns | |
1008 | .HP 5 | |
1009 | .B "nohup command" | |
1010 | .br | |
1011 | The first form can be used in shell scripts to cause hangups to be | |
1012 | ignored for the remainder of the script. | |
1013 | The second form causes the specified command to be run with hangups | |
1014 | ignored. On the Computer Center systems at UC Berkeley, this also | |
1015 | .I submits | |
1016 | the process. | |
1017 | Unless the shell is running detached, | |
1018 | .I nohup | |
1019 | has no effect. | |
1020 | .HP 5 | |
1021 | .B onintr | |
1022 | .br | |
1023 | .ns | |
1024 | .HP 5 | |
1025 | .BR onintr " \-" | |
1026 | .br | |
1027 | .ns | |
1028 | .HP 5 | |
1029 | .BR onintr " label" | |
1030 | .br | |
1031 | Control the action of the shell on interrupts. | |
1032 | The first form restores the default action of the shell on interrupts | |
1033 | which is to terminate shell scripts or to return to the terminal command | |
1034 | input level. | |
1035 | The second form `onintr \-' causes all interrupts to be ignored. | |
1036 | The final form causes the shell to execute a `goto label' when | |
1037 | an interrupt is received or a child process terminates because | |
1038 | it was interrupted. | |
1039 | .IP | |
1040 | In any case, if the shell is running detached and interrupts are | |
1041 | being ignored, all forms of | |
1042 | .I onintr | |
1043 | have no meaning and interrupts | |
1044 | continue to be ignored by the shell and all invoked commands. | |
1045 | .HP 5 | |
1046 | .BR repeat " count command" | |
1047 | .br | |
1048 | The specified | |
1049 | .I command | |
1050 | which is subject to the same restrictions | |
1051 | as the | |
1052 | .I command | |
1053 | in the one line | |
1054 | .I if | |
1055 | statement above, | |
1056 | is executed | |
1057 | .I count | |
1058 | times. | |
1059 | I/O redirections occurs exactly once, even if | |
1060 | .I count | |
1061 | is 0. | |
1062 | .HP 5 | |
1063 | .B set | |
1064 | .br | |
1065 | .ns | |
1066 | .HP 5 | |
1067 | .BR set " name" | |
1068 | .br | |
1069 | .ns | |
1070 | .HP 5 | |
1071 | .BR set " name=word" | |
1072 | .br | |
1073 | .ns | |
1074 | .HP 5 | |
1075 | .BR set " name[index]=word" | |
1076 | .br | |
1077 | .ns | |
1078 | .HP 5 | |
1079 | .BR set " name=(wordlist)" | |
1080 | .br | |
1081 | The first form of the command shows the value of all shell variables. | |
1082 | Variables which have other than a single word as value print as a parenthesized | |
1083 | word list. | |
1084 | The second form sets | |
1085 | .I name | |
1086 | to the null string. | |
1087 | The third form sets | |
1088 | .I name | |
1089 | to the single | |
1090 | .I word. | |
1091 | The fourth form sets | |
1092 | the | |
1093 | .I index'th | |
1094 | component of name to word; | |
1095 | this component must already exist. | |
1096 | The final form sets | |
1097 | .I name | |
1098 | to the list of words in | |
1099 | .I wordlist. | |
1100 | In all cases the value is command and filename expanded. | |
1101 | .IP | |
1102 | These arguments may be repeated to set multiple values in a single set command. | |
1103 | Note however, that variable expansion happens for all arguments before any | |
1104 | setting occurs. | |
1105 | .HP 5 | |
1106 | .BR setenv " name value" | |
1107 | .br | |
1108 | (Version 7 systems only.) | |
1109 | Sets the value of environment variable | |
1110 | .I name | |
1111 | to be | |
1112 | .I value, | |
1113 | a single string. | |
1114 | Useful environment variables are `TERM' the type of your terminal and | |
1115 | `SHELL' the shell you are using. | |
1116 | .HP 5 | |
1117 | .B shift | |
1118 | .br | |
1119 | .ns | |
1120 | .HP 5 | |
1121 | .BR shift " variable" | |
1122 | .br | |
1123 | The members of | |
1124 | .I argv | |
1125 | are shifted to the left, discarding | |
1126 | .I argv[1]. | |
1127 | It is an error for | |
1128 | .I argv | |
1129 | not to be set or to have less than one word as value. | |
1130 | The second form performs the same function on the specified variable. | |
1131 | .HP 5 | |
1132 | .BR source " name" | |
1133 | .br | |
1134 | The shell reads commands from | |
1135 | .I name. | |
1136 | .I Source | |
1137 | commands may be nested; if they are nested too deeply the shell may | |
1138 | run out of file descriptors. | |
1139 | An error in a | |
1140 | .I source | |
1141 | at any level terminates all nested | |
1142 | .I source | |
1143 | commands. | |
1144 | Input during | |
1145 | .I source | |
1146 | commands is | |
1147 | .B never | |
1148 | placed on the history list. | |
1149 | .HP 5 | |
1150 | .BR switch " (string)" | |
1151 | .br | |
1152 | .ns | |
1153 | .HP 5 | |
1154 | .BR case " str1:" | |
1155 | .br | |
1156 | .ns | |
1157 | .HP 5 | |
1158 | \ ... | |
1159 | .br | |
1160 | .ns | |
1161 | .HP 5 | |
1162 | \ | |
1163 | .B breaksw | |
1164 | .br | |
1165 | .ns | |
1166 | .HP 5 | |
1167 | \&... | |
1168 | .br | |
1169 | .ns | |
1170 | .HP 5 | |
1171 | .B default: | |
1172 | .br | |
1173 | .ns | |
1174 | .HP 5 | |
1175 | \ ... | |
1176 | .br | |
1177 | .ns | |
1178 | .HP 5 | |
1179 | \ | |
1180 | .B breaksw | |
1181 | .br | |
1182 | .ns | |
1183 | .HP 5 | |
1184 | .B endsw | |
1185 | .br | |
1186 | Each case label is successively matched, against the specified | |
1187 | .I string | |
1188 | which is first command and filename expanded. | |
1189 | The file metacharacters `*', `?' and `[...]' may be used in the case labels, | |
1190 | which are variable expanded. | |
1191 | If none of the labels match before a `default' label is found, then | |
1192 | the execution begins after the default label. | |
1193 | Each case label and the default label must appear at the beginning of a line. | |
1194 | The command | |
1195 | .I breaksw | |
1196 | causes execution to continue after the | |
1197 | .I endsw. | |
1198 | Otherwise control may fall through case labels and default labels as in C. | |
1199 | If no label matches and there is no default, execution continues after | |
1200 | the | |
1201 | .I endsw. | |
1202 | .HP 5 | |
1203 | .B time | |
1204 | .br | |
1205 | .ns | |
1206 | .HP 5 | |
1207 | .BR time " command" | |
1208 | .br | |
1209 | With no argument, a summary of time used by this shell and its children | |
1210 | is printed. | |
1211 | If arguments are given | |
1212 | the specified simple command is timed and a time summary | |
1213 | as described under the | |
1214 | .I time | |
1215 | variable is printed. | |
1216 | If necessary, an extra shell is created to print the time | |
1217 | statistic when the command completes. | |
1218 | .HP 5 | |
1219 | .B umask | |
1220 | .br | |
1221 | .ns | |
1222 | .HP 5 | |
1223 | .BR umask " value" | |
1224 | .br | |
1225 | The file creation mask is displayed (first form) or set to the specified | |
1226 | value (second form). The mask is given in octal. Common values for | |
1227 | the mask are 002 giving all access to the group and read and execute | |
1228 | access to others or 022 giving all access except no write access for | |
1229 | users in the group or others. | |
1230 | .HP 5 | |
1231 | .BR unalias " pattern" | |
1232 | .br | |
1233 | All aliases whose names match the specified pattern are discarded. | |
1234 | Thus all aliases are removed by `unalias *'. | |
1235 | It is not an error for nothing to be | |
1236 | .I unaliased. | |
1237 | .HP 5 | |
1238 | .BR unset " pattern" | |
1239 | .br | |
1240 | All variables whose names match the specified pattern are removed. | |
1241 | Thus all variables are removed by `unset *'; this has noticeably | |
1242 | distasteful side-effects. | |
1243 | It is not an error for nothing to be | |
1244 | .I unset. | |
1245 | .HP 5 | |
1246 | .B wait | |
1247 | .br | |
1248 | All child processes are waited for. | |
1249 | It the shell is interactive, then an interrupt can disrupt the wait, | |
1250 | at which time the shell prints names and process numbers of all children | |
1251 | known to be outstanding. | |
1252 | .HP 5 | |
1253 | .BR while " (expr)" | |
1254 | .br | |
1255 | .ns | |
1256 | .HP 5 | |
1257 | \ ... | |
1258 | .br | |
1259 | .ns | |
1260 | .HP 5 | |
1261 | .B end | |
1262 | .br | |
1263 | While the specified expression evaluates non-zero, the commands between | |
1264 | the | |
1265 | .I while | |
1266 | and the matching end are evaluated. | |
1267 | .I Break | |
1268 | and | |
1269 | .I continue | |
1270 | may be used to terminate or continue the loop prematurely. | |
1271 | (The | |
1272 | .I while | |
1273 | and | |
1274 | .I end | |
1275 | must appear alone on their input lines.) | |
1276 | Prompting occurs here the first time through the loop as for the | |
1277 | .I foreach | |
1278 | statement if the input is a terminal. | |
1279 | .HP 5 | |
1280 | .B "@" | |
1281 | .br | |
1282 | .ns | |
1283 | .HP 5 | |
1284 | .BR "@" " name = expr" | |
1285 | .br | |
1286 | .ns | |
1287 | .HP 5 | |
1288 | .BR "@" " name[index] = expr" | |
1289 | .br | |
1290 | The first form prints the values of all the shell variables. | |
1291 | The second form sets the specified | |
1292 | .I name | |
1293 | to the value of | |
1294 | .I expr. | |
1295 | If the expression contains `<', `>', `&' or `|' then at least | |
1296 | this part of the expression must be placed within `(' `)'. | |
1297 | The third form assigns the value of | |
1298 | .I expr | |
1299 | to the | |
1300 | .I index'th | |
1301 | argument of | |
1302 | .I name. | |
1303 | Both | |
1304 | .I name | |
1305 | and its | |
1306 | .I index'th | |
1307 | component must already exist. | |
1308 | .IP | |
1309 | The operators `*=', `+=', etc are available as in C. | |
1310 | The space separating the name from the assignment operator is optional. | |
1311 | Spaces are, however, mandatory in separating components of | |
1312 | .I expr | |
1313 | which would otherwise be single words. | |
1314 | .IP | |
1315 | Special postfix `++' and `\-\-' operators increment and decrement | |
1316 | .I name | |
1317 | respectively, i.e. `@ i++'. | |
1318 | .PP | |
1319 | .B "Pre-defined variables" | |
1320 | .PP | |
1321 | The following variables have special meaning to the shell. | |
1322 | Of these, | |
1323 | .I argv, | |
1324 | .I child, | |
1325 | .I home, | |
1326 | .I path, | |
1327 | .I prompt, | |
1328 | .I shell | |
1329 | and | |
1330 | .I status | |
1331 | are always set by the shell. | |
1332 | Except for | |
1333 | .I child | |
1334 | and | |
1335 | .I status | |
1336 | this setting occurs only at initialization; | |
1337 | these variables will not then be modified unless this is done | |
1338 | explicitly by the user. | |
1339 | .TP 15 | |
1340 | .B argv | |
1341 | \c | |
1342 | Set to the arguments to the shell, it is from this variable that | |
1343 | positional parameters are substituted, i.e. `$1' is replaced by | |
1344 | `$argv[1]', etc. | |
1345 | .TP 15 | |
1346 | .B child | |
1347 | The process number printed when the last command was forked with `&'. | |
1348 | This variable is | |
1349 | .I unset | |
1350 | when this process terminates. | |
1351 | .TP 15 | |
1352 | .B echo | |
1353 | \c | |
1354 | Set when the | |
1355 | .B \-x | |
1356 | command line option is given. | |
1357 | Causes each command and its arguments | |
1358 | to be echoed just before it is executed. | |
1359 | For non-builtin commands all expansions occur before echoing. | |
1360 | Builtin commands are echoed before command and filename substitution, | |
1361 | since these substitutions are then done selectively. | |
1362 | .TP 15 | |
1363 | .B history | |
1364 | \c | |
1365 | Can be given a numeric value to control the size of the history list. | |
1366 | Any command which has been referenced in this many events will not be | |
1367 | discarded. | |
1368 | Too large values of | |
1369 | .I history | |
1370 | may run the shell out of memory. | |
1371 | The last executed command is always saved on the history list. | |
1372 | .TP 15 | |
1373 | .B home | |
1374 | \c | |
1375 | The home directory of the invoker, initialized from the environment. | |
1376 | The filename expansion of `\fB~\fR' refers to this variable. | |
1377 | .TP 15 | |
1378 | .B ignoreeof | |
1379 | \c | |
1380 | If set the shell ignores | |
1381 | end-of-file from input devices which are terminals. | |
1382 | This prevents shells from accidentally being killed by control-D's. | |
1383 | .TP 15 | |
1384 | .B mail | |
1385 | \c | |
1386 | The files where the shell checks for mail. | |
1387 | This is done after each command completion which will result in a prompt, | |
1388 | if a specified interval has elapsed. | |
1389 | The shell says `You have new mail.' | |
1390 | if the file exists with an access time not greater than its modify time. | |
1391 | .IP | |
1392 | If the first word of the value of | |
1393 | .I mail | |
1394 | is numeric it specifies a different mail checking interval, in seconds, | |
1395 | than the default, which is 10 minutes. | |
1396 | .IP | |
1397 | If multiple mail files are specified, then the shell says | |
1398 | `New mail in | |
1399 | .IR name ' | |
1400 | when there is mail in the file | |
1401 | .I name. | |
1402 | .TP 15 | |
1403 | .B noclobber | |
1404 | \c | |
1405 | As described in the section on | |
1406 | .I Input/output, | |
1407 | restrictions are placed on output redirection to insure that | |
1408 | files are not accidentally destroyed, and that `>>' redirections | |
1409 | refer to existing files. | |
1410 | .TP 15 | |
1411 | .B noglob | |
1412 | \c | |
1413 | If set, filename expansion is inhibited. | |
1414 | This is most useful in shell scripts which are not dealing with filenames, | |
1415 | or after a list of filenames has been obtained and further expansions | |
1416 | are not desirable. | |
1417 | .TP 15 | |
1418 | .B nonomatch | |
1419 | \c | |
1420 | If set, it is not an error for a filename expansion to not match any | |
1421 | existing files; rather the primitive pattern is returned. | |
1422 | It is still an error for the primitive pattern to be malformed, i.e. | |
1423 | `echo [' still gives an error. | |
1424 | .TP 15 | |
1425 | .B path | |
1426 | \c | |
1427 | Each word of the path variable specifies a directory in which | |
1428 | commands are to be sought for execution. | |
1429 | A null word specifies the current directory. | |
1430 | If there is no | |
1431 | .I path | |
1432 | variable then only full path names will execute. | |
1433 | The usual search path is `.', `/bin' and `/usr/bin', but this | |
1434 | may vary from system to system. | |
1435 | For the super-user the default search path is `/etc', `/bin' and `/usr/bin'. | |
1436 | .TP 15 | |
1437 | .B prompt | |
1438 | \c | |
1439 | The string which is printed before each command is read from | |
1440 | an interactive terminal input. | |
1441 | If a `!' appears in the string it will be replaced by the current event number | |
1442 | unless a preceding `\e' is given. | |
1443 | Default is `% ', or `# ' for the super-user. | |
1444 | .TP 15 | |
1445 | .B shell | |
1446 | \c | |
1447 | The file in which the shell resides. | |
1448 | This is used in forking shells to interpret files which have execute | |
1449 | bits set, but which are not executable by the system. | |
1450 | (See the description of | |
1451 | .I "Non-builtin Command Execution" | |
1452 | below.) | |
1453 | Initialized to the (system-dependent) home of the shell. | |
1454 | .TP 15 | |
1455 | .B status | |
1456 | \c | |
1457 | The status returned by the last command. | |
1458 | If it terminated abnormally, then 0200 is added to the status. | |
1459 | Builtin commands which fail return exit status `1', | |
1460 | all other builtin commands set status `0'. | |
1461 | .TP 15 | |
1462 | .B time | |
1463 | \c | |
1464 | Controls automatic timing of commands. | |
1465 | If set, then any command which takes more than this many cpu seconds | |
1466 | will cause a line giving user, system, and real times and a utilization | |
1467 | percentage which is the ratio of user plus system times to real time | |
1468 | to be printed when it terminates. | |
1469 | .TP 15 | |
1470 | .B verbose | |
1471 | \c | |
1472 | Set by the | |
1473 | .B \-v | |
1474 | command line option, causes the words of each command to be printed | |
1475 | after history substitution. | |
1476 | .PP | |
1477 | .B "Non-builtin command execution" | |
1478 | .PP | |
1479 | When a command to be executed is found to not be a builtin command | |
1480 | the shell attempts to execute the command via | |
1481 | .IR exec (2). | |
1482 | Each word in the variable | |
1483 | .I path | |
1484 | names a directory which | |
1485 | the shell concatenates with the given command name to form a path name | |
1486 | of a file which it then attempts to execute. | |
1487 | Parenthesized commands are always executed in a subshell. | |
1488 | Thus `(cd ; pwd) ; pwd' prints the | |
1489 | .I home | |
1490 | directory; leaving you where you were (printing this after the home directory), | |
1491 | while `cd ; pwd' leaves you in the | |
1492 | .I home | |
1493 | directory. | |
1494 | Parenthesized commands are most often used to prevent | |
1495 | .I chdir | |
1496 | from affecting the current shell. | |
1497 | .PP | |
1498 | If the file has execute permissions but is not an | |
1499 | executable binary to the system, then it is assumed to be a | |
1500 | file containing shell commands an a new shell is spawned to read it. | |
1501 | .PP | |
1502 | If there is an | |
1503 | .I alias | |
1504 | for | |
1505 | .I shell | |
1506 | then the words of the alias will be prepended to the argument list to form | |
1507 | the shell command. | |
1508 | The first word of the | |
1509 | .I alias | |
1510 | should be the full path name of the shell | |
1511 | (e.g. `$shell'). | |
1512 | Note that this is a special, late occurring, case of | |
1513 | .I alias | |
1514 | substitution, | |
1515 | and only allows words to be prepended to the argument list without modification. | |
1516 | .PP | |
1517 | .B "Argument list processing" | |
1518 | .PP | |
1519 | If argument 0 to the shell is `\-' then this | |
1520 | is a login shell. | |
1521 | The flag arguments are interpreted as follows: | |
1522 | .TP 5 | |
1523 | .B \-c | |
1524 | \c | |
1525 | Commands are read from the (single) following argument which must | |
1526 | be present. | |
1527 | Any remaining arguments are placed in | |
1528 | .I argv. | |
1529 | .TP 5 | |
1530 | .B \-e | |
1531 | \c | |
1532 | The shell exits if any invoked command terminates abnormally | |
1533 | or yields a non-zero exit status. | |
1534 | .TP 5 | |
1535 | .B \-f | |
1536 | \c | |
1537 | The shell will start faster, because it will neither search for nor | |
1538 | execute commands from the file | |
1539 | `\&.cshrc' in the invokers home directory. | |
1540 | .TP 5 | |
1541 | .B \-i | |
1542 | \c | |
1543 | The shell is interactive and prompts for its top-level input, | |
1544 | even if it appears to not be a terminal. | |
1545 | Shells are interactive without this option if their inputs | |
1546 | and outputs are terminals. | |
1547 | .TP 5 | |
1548 | .B \-n | |
1549 | \c | |
1550 | Commands are parsed, but not executed. | |
1551 | This may aid in syntactic checking of shell scripts. | |
1552 | .TP 5 | |
1553 | .B \-s | |
1554 | \c | |
1555 | Command input is taken from the standard input. | |
1556 | .TP 5 | |
1557 | .B \-t | |
1558 | \c | |
1559 | A single line of input is read and executed. | |
1560 | A `\e' may be used to escape the newline at the end of this | |
1561 | line and continue onto another line. | |
1562 | .TP 5 | |
1563 | .B \-v | |
1564 | \c | |
1565 | Causes the | |
1566 | .I verbose | |
1567 | variable to be set, with the effect | |
1568 | that command input is echoed after history substitution. | |
1569 | .TP 5 | |
1570 | .B \-x | |
1571 | \c | |
1572 | Causes the | |
1573 | .I echo | |
1574 | variable to be set, so that commands are echoed immediately before execution. | |
1575 | .TP 5 | |
1576 | .B \-V | |
1577 | \c | |
1578 | Causes the | |
1579 | .I verbose | |
1580 | variable to be set even before `\&.cshrc' is executed. | |
1581 | .TP 5 | |
1582 | .B \-X | |
1583 | \c | |
1584 | Is to | |
1585 | .B \-x | |
1586 | as | |
1587 | .B \-V | |
1588 | is to | |
1589 | .B \-v. | |
1590 | .PP | |
1591 | After processing of flag arguments if arguments remain but none of the | |
1592 | .B \-c, | |
1593 | .B \-i, | |
1594 | .B \-s, | |
1595 | or | |
1596 | .B \-t | |
1597 | options was given the first argument is taken as the name of a file of | |
1598 | commands to be executed. | |
1599 | The shell opens this file, and saves its name for possible resubstitution | |
1600 | by `$0'. | |
1601 | Since many systems use either the standard version 6 or version 7 shells | |
1602 | whose shell scripts are not compatible with this shell, the shell will | |
1603 | execute such a `standard' shell if the first character of a script | |
1604 | is not a `#', i.e. if the script does not start with a comment. | |
1605 | Remaining arguments initialize the variable | |
1606 | .I argv. | |
1607 | .PP | |
1608 | .B "Signal handling" | |
1609 | .PP | |
1610 | The shell normally ignores | |
1611 | .I quit | |
1612 | signals. | |
1613 | The | |
1614 | .I interrupt | |
1615 | and | |
1616 | .I quit | |
1617 | signals are ignored for an invoked command | |
1618 | if the command is followed by `&'; | |
1619 | otherwise the signals have the values which the shell inherited | |
1620 | from its parent. | |
1621 | The shells handling of interrupts can be controlled by | |
1622 | .I onintr. | |
1623 | Login shells catch the | |
1624 | .I terminate | |
1625 | signal; otherwise this signal is passed on to children from the state in the | |
1626 | shell's parent. | |
1627 | In no case are interrupts allowed when a login shell is reading the file | |
1628 | `\&.logout'. | |
1629 | .SH AUTHOR | |
1630 | William Joy | |
1631 | .SH FILES | |
1632 | .DT | |
1633 | .nf | |
1634 | ~/.cshrc Read at beginning of execution by each shell. | |
1635 | ~/.login Read by login shell, after `.cshrc' at login. | |
1636 | ~/.logout Read by login shell, at logout. | |
1637 | /bin/sh Standard shell, for shell scripts not starting with a `#'. | |
1638 | /tmp/sh* Temporary file for `<<'. | |
1639 | /dev/null Source of empty file. | |
1640 | /etc/passwd Source of home directories for `~name'. | |
1641 | .fi | |
1642 | .SH LIMITATIONS | |
1643 | Words can be no longer that 512 characters. | |
1644 | The number of characters in an argument varies from system to system. | |
1645 | Early version 6 systems typically have 512 character limits | |
1646 | while later version 6 and version 7 systems have 5120 character limits. | |
1647 | The number of arguments to a command which involves filename expansion | |
1648 | is limited to 1/6'th the number of characters allowed in an argument list. | |
1649 | Also command substitutions may substitute no more characters than are | |
1650 | allowed in an argument list. | |
1651 | .PP | |
1652 | To detect looping, the shell restricts the number of | |
1653 | .I alias | |
1654 | substititutions on a single line to 20. | |
1655 | .SH "SEE ALSO" | |
1656 | access(2), exec(2), fork(2), pipe(2), signal(2), umask(2), wait(2), | |
1657 | a.out(5), environ(5), | |
1658 | `An introduction to the C shell' | |
1659 | .SH BUGS | |
1660 | Control structure should be parsed rather than being recognized as built-in | |
1661 | commands. This would allow control commands to be placed anywhere, | |
1662 | to be combined with `|', and to be used with `&' and `;' metasyntax. | |
1663 | .PP | |
1664 | Commands within loops, prompted for by `?', are not placed in the | |
1665 | .I history | |
1666 | list. | |
1667 | .PP | |
1668 | It should be possible to use the `:' modifiers on the output of command | |
1669 | substitutions. | |
1670 | All and more than one `:' modifier should be allowed on `$' substitutions. | |
1671 | .PP | |
1672 | Some commands should not touch | |
1673 | .I status | |
1674 | or it may be so transient as to be almost useless. | |
1675 | Oring in 0200 to | |
1676 | .I status | |
1677 | on abnormal termination is a kludge. | |
1678 | .PP | |
1679 | In order to be able to recover from failing | |
1680 | .I exec | |
1681 | commands on version 6 systems, the new command inherits several | |
1682 | open files other than the normal standard input and output and diagnostic | |
1683 | output. | |
1684 | If the input and output are redirected and the new command does not | |
1685 | close these files, some files may be held open unnecessarily. |