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