Commit | Line | Data |
---|---|---|
6febb542 WJ |
1 | .\" Copyright (c) 1980, 1990 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)csh.1 6.17 (Berkeley) 6/7/91 | |
33 | .\" | |
34 | .Dd June 7, 1991 | |
35 | .Dt CSH 1 | |
36 | .Os BSD 4 | |
37 | .Sh NAME | |
38 | .Nm csh | |
39 | .Nd a shell (command interpreter) with C-like syntax | |
40 | .Sh SYNOPSIS | |
41 | .Nm csh | |
42 | .Op Fl bcefinstvVxX | |
43 | .Op arg ... | |
44 | .Sh DESCRIPTION | |
45 | The | |
46 | .Nm Csh | |
47 | is a command language interpreter | |
48 | incorporating a history mechanism (see | |
49 | .Nm History Substitutions ) , | |
50 | job control facilities (see | |
51 | .Nm Jobs ) , | |
52 | interactive file name | |
53 | and user name completion (see | |
54 | .Nm File Name Completion ) , | |
55 | and a C-like syntax. It is used both as an interactive | |
56 | login shell and a shell script command processor. | |
57 | .Ss Argument list processing | |
58 | If the first argument (argument 0) to the shell is | |
59 | .Ql Fl | |
60 | then this | |
61 | is a login shell. | |
62 | The flag arguments are interpreted as follows: | |
63 | .Bl -tag -width 5n | |
64 | .It Fl b | |
65 | This flag forces a ``break'' from option processing, causing any further | |
66 | shell arguments to be treated as non-option arguments. | |
67 | The remaining arguments will not be interpreted as shell options. | |
68 | This may be used to pass options to a shell script without confusion | |
69 | or possible subterfuge. | |
70 | The shell will not run a set-user ID script without this option. | |
71 | .It Fl c | |
72 | Commands are read from the (single) following argument which must | |
73 | be present. | |
74 | Any remaining arguments are placed in | |
75 | .Ar argv . | |
76 | .It Fl e | |
77 | The shell exits if any invoked command terminates abnormally | |
78 | or yields a non-zero exit status. | |
79 | .It Fl f | |
80 | The shell will start faster, because it will neither search for nor | |
81 | execute commands from the file | |
82 | .Pa \&.cshrc | |
83 | in the invoker's home directory. | |
84 | .It Fl i | |
85 | The shell is interactive and prompts for its top-level input, | |
86 | even if it appears to not be a terminal. | |
87 | Shells are interactive without this option if their inputs | |
88 | and outputs are terminals. | |
89 | .It Fl n | |
90 | Commands are parsed, but not executed. | |
91 | This aids in syntactic checking of shell scripts. | |
92 | .It Fl s | |
93 | Command input is taken from the standard input. | |
94 | .It Fl t | |
95 | A single line of input is read and executed. | |
96 | A | |
97 | .Ql \e | |
98 | may be used to escape the newline at the end of this | |
99 | line and continue onto another line. | |
100 | .It Fl v | |
101 | Causes the | |
102 | .Ar verbose | |
103 | variable to be set, with the effect | |
104 | that command input is echoed after history substitution. | |
105 | .It Fl x | |
106 | Causes the | |
107 | .Ar echo | |
108 | variable to be set, so that commands are echoed immediately before execution. | |
109 | .It Fl V | |
110 | Causes the | |
111 | .Ar verbose | |
112 | variable to be set even before | |
113 | .Pa .cshrc | |
114 | is executed. | |
115 | .It Fl X | |
116 | Is to | |
117 | .Fl x | |
118 | as | |
119 | .Fl V | |
120 | is to | |
121 | .Fl v . | |
122 | .El | |
123 | .Pp | |
124 | After processing of flag arguments, if arguments remain but none of the | |
125 | .Fl c , | |
126 | .Fl i , | |
127 | .Fl s , | |
128 | or | |
129 | .Fl t | |
130 | options were given, the first argument is taken as the name of a file of | |
131 | commands to be executed. | |
132 | The shell opens this file, and saves its name for possible resubstitution | |
133 | by `$0'. | |
134 | Since many systems use either the standard version 6 or version 7 shells | |
135 | whose shell scripts are not compatible with this shell, the shell will | |
136 | execute such a `standard' shell if the first character of a script | |
137 | is not a `#', i.e. if the script does not start with a comment. | |
138 | Remaining arguments initialize the variable | |
139 | .Ar argv . | |
140 | .Pp | |
141 | An instance of | |
142 | .Nm csh | |
143 | begins by executing commands from the file | |
144 | .Pa /etc/csh.cshrc | |
145 | and, | |
146 | if this is a login shell, | |
147 | .Pa \&/etc/csh.login . | |
148 | It then executes | |
149 | commands from | |
150 | .Pa \&.cshrc | |
151 | in the | |
152 | .Ar home | |
153 | directory of the invoker, and, if this is a login shell, the file | |
154 | .Pa \&.login | |
155 | in the same location. | |
156 | It is typical for users on crt's to put the command ``stty crt'' | |
157 | in their | |
158 | .Pa \&.login | |
159 | file, and to also invoke | |
160 | .Xr tset 1 | |
161 | there. | |
162 | .Pp | |
163 | In the normal case, the shell will begin reading commands from the | |
164 | terminal, prompting with `% '. | |
165 | Processing of arguments and the use of the shell to process files | |
166 | containing command scripts will be described later. | |
167 | .Pp | |
168 | The shell repeatedly performs the following actions: | |
169 | a line of command input is read and broken into | |
170 | .Ar words . | |
171 | This sequence of words is placed on the command history list and parsed. | |
172 | Finally each command in the current line is executed. | |
173 | .Pp | |
174 | When a login shell terminates it executes commands from the files | |
175 | .Pa .logout | |
176 | in the user's | |
177 | .Ar home | |
178 | directory and | |
179 | .Pa /etc/csh.logout . | |
180 | .Ss Lexical structure | |
181 | The shell splits input lines into words at blanks and tabs with the | |
182 | following exceptions. | |
183 | The characters | |
184 | `&' `\&|' `;' `<' `>' `(' `)' | |
185 | form separate words. | |
186 | If doubled in `&&', `\&|\&|', `<<' or `>>' these pairs form single words. | |
187 | These parser metacharacters may be made part of other words, or prevented their | |
188 | special meaning, by preceding them with `\e'. | |
189 | A newline preceded by a `\e' is equivalent to a blank. | |
190 | .Pp | |
191 | Strings enclosed in matched pairs of quotations, | |
192 | `\*(aa', `\*(ga' or `"', | |
193 | form parts of a word; metacharacters in these strings, including blanks | |
194 | and tabs, do not form separate words. | |
195 | These quotations have semantics to be described subsequently. | |
196 | Within pairs of `\'' or `"' characters a newline preceded by a `\e' gives | |
197 | a true newline character. | |
198 | .Pp | |
199 | When the shell's input is not a terminal, | |
200 | the character `#' introduces a comment which continues to the end of the | |
201 | input line. | |
202 | It is prevented this special meaning when preceded by `\e' | |
203 | and in quotations using `\`', `\'', and `"'. | |
204 | .Ss Commands | |
205 | A simple command is a sequence of words, the first of which | |
206 | specifies the command to be executed. | |
207 | A simple command or | |
208 | a sequence of simple commands separated by `\&|' characters | |
209 | forms a pipeline. | |
210 | The output of each command in a pipeline is connected to the input of the next. | |
211 | Sequences of pipelines may be separated by `;', and are then executed | |
212 | sequentially. | |
213 | A sequence of pipelines may be executed without immediately | |
214 | waiting for it to terminate by following it with an `&'. | |
215 | .Pp | |
216 | Any of the above may be placed in `(' `)' to form a simple command (which | |
217 | may be a component of a pipeline, etc.) | |
218 | It is also possible to separate pipelines with `\&|\&|' or `&&' indicating, | |
219 | as in the C language, | |
220 | that the second is to be executed only if the first fails or succeeds | |
221 | respectively. (See | |
222 | .Em Expressions . ) | |
223 | .Ss Jobs | |
224 | The shell associates a | |
225 | .Ar job | |
226 | with each pipeline. It keeps | |
227 | a table of current jobs, printed by the | |
228 | .Ar jobs | |
229 | command, and assigns them small integer numbers. When | |
230 | a job is started asynchronously with `&', the shell prints a line which looks | |
231 | like: | |
232 | .Bd -filled -offset indent | |
233 | .Op 1 | |
234 | 1234 | |
235 | .Ed | |
236 | .Pp | |
237 | indicating that the job which was started asynchronously was job number | |
238 | 1 and had one (top-level) process, whose process id was 1234. | |
239 | .Pp | |
240 | If you are running a job and wish to do something else you may hit the key | |
241 | .Nm ^Z | |
242 | (control-Z) which sends a STOP signal to the current job. | |
243 | The shell will then normally indicate that the job has been `Stopped', | |
244 | and print another prompt. You can then manipulate the state of this job, | |
245 | putting it in the | |
246 | .Em background | |
247 | with the | |
248 | .Ar bg | |
249 | command, or run some other | |
250 | commands and then eventually bring the job back into the foreground with | |
251 | the | |
252 | .Em foreground | |
253 | command | |
254 | .Ar fg . | |
255 | A | |
256 | .Nm ^Z | |
257 | takes effect immediately and | |
258 | is like an interrupt in that pending output and unread input are discarded | |
259 | when it is typed. There is another special key | |
260 | .Nm ^Y | |
261 | which does | |
262 | not generate a STOP signal until a program attempts to | |
263 | .Xr read 2 | |
264 | it. | |
265 | This can usefully be typed ahead when you have prepared some commands | |
266 | for a job which you wish to stop after it has read them. | |
267 | .Pp | |
268 | A job being run in the background will stop if it tries to read | |
269 | from the terminal. Background jobs are normally allowed to produce output, | |
270 | but this can be disabled by giving the command ``stty tostop''. | |
271 | If you set this | |
272 | tty option, then background jobs will stop when they try to produce | |
273 | output like they do when they try to read input. | |
274 | .Pp | |
275 | There are several ways to refer to jobs in the shell. The character | |
276 | `%' introduces a job name. If you wish to refer to job number 1, you can | |
277 | name it as `%1'. Just naming a job brings it to the foreground; thus | |
278 | `%1' is a synonym for `fg %1', bringing job 1 back into the foreground. | |
279 | Similarly saying `%1 &' resumes job 1 in the background. | |
280 | Jobs can also be named by prefixes of the string typed in to start them, | |
281 | if these prefixes are unambiguous, thus `%ex' would normally restart | |
282 | a suspended | |
283 | .Xr ex 1 | |
284 | job, if there were only one suspended job whose name began with | |
285 | the string `ex'. It is also possible to say `%?string' | |
286 | which specifies a job whose text contains | |
287 | .Ar string , | |
288 | if there is only one such job. | |
289 | .Pp | |
290 | The shell maintains a notion of the current and previous jobs. | |
291 | In output pertaining to jobs, the current job is marked with a `+' | |
292 | and the previous job with a `\-'. The abbreviation `%+' refers | |
293 | to the current job and `%\-' refers to the previous job. For close | |
294 | analogy with the syntax of the | |
295 | .Ar history | |
296 | mechanism (described below), | |
297 | `%%' is also a synonym for the current job. | |
298 | .Pp | |
299 | The job control mechanism requires that the | |
300 | .Xr stty 1 | |
301 | option | |
302 | .Ic new | |
303 | be set. It is an artifact from a | |
304 | .Em new | |
305 | implementation | |
306 | of the | |
307 | tty driver which allows generation of interrupt characters from | |
308 | the keyboard to tell jobs to stop. See stty(1) for details | |
309 | on setting options in the new tty driver. | |
310 | .Ss Status reporting | |
311 | This shell learns immediately whenever a process changes state. | |
312 | It normally informs you whenever a job becomes blocked so that | |
313 | no further progress is possible, but only just before it prints | |
314 | a prompt. This is done so that it does not otherwise disturb your work. | |
315 | If, however, you set the shell variable | |
316 | .Ar notify , | |
317 | the shell will notify you immediately of changes of status in background | |
318 | jobs. | |
319 | There is also a shell command | |
320 | .Ar notify | |
321 | which marks a single process so that its status changes will be immediately | |
322 | reported. By default | |
323 | .Ar notify | |
324 | marks the current process; | |
325 | simply say `notify' after starting a background job to mark it. | |
326 | .Pp | |
327 | When you try to leave the shell while jobs are stopped, you will | |
328 | be warned that `You have stopped jobs.' You may use the | |
329 | .Ar jobs | |
330 | command to see what they are. If you do this or immediately try to | |
331 | exit again, the shell will not warn you a second time, and the suspended | |
332 | jobs will be terminated. | |
333 | .Ss File Name Completion | |
334 | When the file name completion feature is enabled by setting | |
335 | the shell variable | |
336 | .Ar filec | |
337 | (see | |
338 | .Ic set ) , | |
339 | .Nm csh | |
340 | will | |
341 | interactively complete file names and user names from unique | |
342 | prefixes, when they are input from the terminal followed by | |
343 | the escape character (the escape key, or control-[) | |
344 | For example, | |
345 | if the current directory looks like | |
346 | .Bd -literal -offset indent | |
347 | DSC.OLD bin cmd lib xmpl.c | |
348 | DSC.NEW chaosnet cmtest mail xmpl.o | |
349 | bench class dev mbox xmpl.out | |
350 | .Ed | |
351 | .Pp | |
352 | and the input is | |
353 | .Pp | |
354 | .Dl % vi ch<escape> | |
355 | .Pp | |
356 | .Nm csh | |
357 | will complete the prefix ``ch'' | |
358 | to the only matching file name ``chaosnet'', changing the input | |
359 | line to | |
360 | .Pp | |
361 | .Dl % vi chaosnet | |
362 | .Pp | |
363 | However, given | |
364 | .Pp | |
365 | .Dl % vi D<escape> | |
366 | .Pp | |
367 | .Nm csh | |
368 | will only expand the input to | |
369 | .Pp | |
370 | .Dl % vi DSC. | |
371 | .Pp | |
372 | and will sound the terminal bell to indicate that the expansion is | |
373 | incomplete, since there are two file names matching the prefix ``D''. | |
374 | .Pp | |
375 | If a partial file name is followed by the end-of-file character | |
376 | (usually control-D), then, instead of completing the name, | |
377 | .Nm csh | |
378 | will list all file names matching the prefix. For example, | |
379 | the input | |
380 | .Pp | |
381 | .Dl % vi D<control-D> | |
382 | .Pp | |
383 | causes all files beginning with ``D'' to be listed: | |
384 | .Pp | |
385 | .Dl DSC.NEW DSC.OLD | |
386 | .Pp | |
387 | while the input line remains unchanged. | |
388 | .Pp | |
389 | The same system of escape and end-of-file can also be used to | |
390 | expand partial user names, if the word to be completed | |
391 | (or listed) begins with the character ``~''. For example, | |
392 | typing | |
393 | .Pp | |
394 | .Dl cd ~ro<escape> | |
395 | .Pp | |
396 | may produce the expansion | |
397 | .Pp | |
398 | .Dl cd ~root | |
399 | .Pp | |
400 | The use of the terminal bell to signal errors or multiple matches | |
401 | can be inhibited by setting the variable | |
402 | .Ar nobeep . | |
403 | .Pp | |
404 | Normally, all files in the particular directory are candidates | |
405 | for name completion. Files with certain suffixes can be excluded | |
406 | from consideration by setting the variable | |
407 | .Ar fignore | |
408 | to the | |
409 | list of suffixes to be ignored. Thus, if | |
410 | .Ar fignore | |
411 | is set by | |
412 | the command | |
413 | .Pp | |
414 | .Dl % set fignore = (.o .out) | |
415 | .Pp | |
416 | then typing | |
417 | .Pp | |
418 | .Dl % vi x<escape> | |
419 | .Pp | |
420 | would result in the completion to | |
421 | .Pp | |
422 | .Dl % vi xmpl.c | |
423 | .Pp | |
424 | ignoring the files "xmpl.o" and "xmpl.out". | |
425 | However, if the only completion possible requires not ignoring these | |
426 | suffixes, then they are not ignored. In addition, | |
427 | .Ar fignore | |
428 | does not affect the listing of file names by control-D. All files | |
429 | are listed regardless of their suffixes. | |
430 | .Ss Substitutions | |
431 | We now describe the various transformations the shell performs on the | |
432 | input in the order in which they occur. | |
433 | .Ss History substitutions | |
434 | History substitutions place words from previous command input as portions | |
435 | of new commands, making it easy to repeat commands, repeat arguments | |
436 | of a previous command in the current command, or fix spelling mistakes | |
437 | in the previous command with little typing and a high degree of confidence. | |
438 | History substitutions begin with the character `!' and may begin | |
439 | .Ar anywhere | |
440 | in the input stream (with the proviso that they | |
441 | .Nm "do not" | |
442 | nest.) | |
443 | This `!' may be preceded by an `\e' to prevent its special meaning; for | |
444 | convenience, a `!' is passed unchanged when it is followed by a blank, | |
445 | tab, newline, `=' or `('. | |
446 | (History substitutions also occur when an input line begins with `\*(ua'. | |
447 | This special abbreviation will be described later.) | |
448 | Any input line which contains history substitution is echoed on the terminal | |
449 | before it is executed as it could have been typed without history substitution. | |
450 | .Pp | |
451 | Commands input from the terminal which consist of one or more words | |
452 | are saved on the history list. | |
453 | The history substitutions reintroduce sequences of words from these | |
454 | saved commands into the input stream. | |
455 | The size of which is controlled by the | |
456 | .Ar history | |
457 | variable; the previous command is always retained, regardless of its value. | |
458 | Commands are numbered sequentially from 1. | |
459 | .Pp | |
460 | For definiteness, consider the following output from the | |
461 | .Ar history | |
462 | command: | |
463 | .Bd -literal -offset indent | |
464 | \09 write michael | |
465 | 10 ex write.c | |
466 | 11 cat oldwrite.c | |
467 | 12 diff *write.c | |
468 | .Ed | |
469 | .Pp | |
470 | The commands are shown with their event numbers. | |
471 | It is not usually necessary to use event numbers, but the current event | |
472 | number can be made part of the | |
473 | .Ar prompt | |
474 | by placing an `!' in the prompt string. | |
475 | .Pp | |
476 | With the current event 13 we can refer to previous events by event | |
477 | number `!11', relatively as in `!\-2' (referring to the same event), | |
478 | by a prefix of a command word | |
479 | as in `!d' for event 12 or `!wri' for event 9, or by a string contained in | |
480 | a word in the command as in `!?mic?' also referring to event 9. | |
481 | These forms, without further modification, simply reintroduce the words | |
482 | of the specified events, each separated by a single blank. | |
483 | As a special case `!!' refers to the previous command; thus `!!' | |
484 | alone is essentially a | |
485 | .Ar redo . | |
486 | .Pp | |
487 | To select words from an event we can follow the event specification by | |
488 | a `:' and a designator for the desired words. | |
489 | The words of an input line are numbered from 0, | |
490 | the first (usually command) word being 0, the second word (first argument) | |
491 | being 1, etc. | |
492 | The basic word designators are: | |
493 | .Pp | |
494 | .Bl -tag -width Ds -compact -offset indent | |
495 | .It \&0 | |
496 | first (command) word | |
497 | .It Ar n | |
498 | .Ar n Ns \'th | |
499 | argument | |
500 | .It \*(ua | |
501 | first argument, i.e. `1' | |
502 | .It $ | |
503 | last argument | |
504 | .It % | |
505 | word matched by (immediately preceding) | |
506 | .No \&? Ns Ar s Ns \? | |
507 | search | |
508 | .It Ar \&x\-y | |
509 | range of words | |
510 | .It Ar \&\-y | |
511 | abbreviates | |
512 | .Ar `\&0\-y\' | |
513 | .It * | |
514 | abbreviates `\*(ua\-$', or nothing if only 1 word in event | |
515 | .It Ar x* | |
516 | abbreviates | |
517 | .Ar `x\-$\' | |
518 | .It Ar x\- | |
519 | like | |
520 | .Ar `x*\' | |
521 | but omitting word `$' | |
522 | .El | |
523 | .Pp | |
524 | The `:' separating the event specification from the word designator | |
525 | can be omitted if the argument selector begins with a `\*(ua', `$', `*' | |
526 | `\-' or `%'. | |
527 | After the optional word designator can be | |
528 | placed a sequence of modifiers, each preceded by a `:'. | |
529 | The following modifiers are defined: | |
530 | .Pp | |
531 | .Bl -tag -width Ds -compact -offset indent | |
532 | .It h | |
533 | Remove a trailing pathname component, leaving the head. | |
534 | .It r | |
535 | Remove a trailing `.xxx' component, leaving the root name. | |
536 | .It e | |
537 | Remove all but the extension `.xxx' part. | |
538 | .It s Ns Ar /l/r/ | |
539 | Substitute | |
540 | .Ar l | |
541 | for | |
542 | .Ar r | |
543 | .It t | |
544 | Remove all leading pathname components, leaving the tail. | |
545 | .It \&& | |
546 | Repeat the previous substitution. | |
547 | .It g | |
548 | Apply the change globally, prefixing the above, e.g. `g&'. | |
549 | .It p | |
550 | Print the new command line but do not execute it. | |
551 | .It q | |
552 | Quote the substituted words, preventing further substitutions. | |
553 | .It x | |
554 | Like q, but break into words at blanks, tabs and newlines. | |
555 | .El | |
556 | .Pp | |
557 | Unless preceded by a `g' the modification is applied only to the first | |
558 | modifiable word. With substitutions, it is an error for no word to be | |
559 | applicable. | |
560 | .Pp | |
561 | The left hand side of substitutions are not regular expressions in the sense | |
562 | of the editors, but rather strings. | |
563 | Any character may be used as the delimiter in place of `/'; | |
564 | a `\e' quotes the delimiter into the | |
565 | .Ar l " " | |
566 | and | |
567 | .Ar r " " | |
568 | strings. | |
569 | The character `&' in the right hand side is replaced by the text from | |
570 | the left. | |
571 | A `\e' quotes `&' also. | |
572 | A null | |
573 | .Ar l | |
574 | (" ") | |
575 | uses the previous string either from a | |
576 | .Ar l | |
577 | or from a | |
578 | contextual scan string | |
579 | .Ar s | |
580 | in `!? | |
581 | .Ar s | |
582 | \?'. | |
583 | The trailing delimiter in the substitution may be omitted if a newline | |
584 | follows immediately as may the trailing `?' in a contextual scan. | |
585 | .Pp | |
586 | A history reference may be given without an event specification, e.g. `!$'. | |
587 | In this case the reference is to the previous command unless a previous | |
588 | history reference occurred on the same line in which case this form repeats | |
589 | the previous reference. | |
590 | Thus `!?foo?\*(ua !$' gives the first and last arguments | |
591 | from the command matching `?foo?'. | |
592 | .Pp | |
593 | A special abbreviation of a history reference occurs when the first | |
594 | non-blank character of an input line is a `\*(ua'. | |
595 | This is equivalent to `!:s\*(ua' providing a convenient shorthand for substitutions | |
596 | on the text of the previous line. | |
597 | Thus `\*(ualb\*(ualib' fixes the spelling of | |
598 | `lib' | |
599 | in the previous command. | |
600 | Finally, a history substitution may be surrounded with `{' and `}' | |
601 | if necessary to insulate it from the characters which follow. | |
602 | Thus, after `ls \-ld ~paul' we might do `!{l}a' to do `ls \-ld ~paula', | |
603 | while `!la' would look for a command starting `la'. | |
604 | .Pp | |
605 | .Ss Quotations with \' and \&" | |
606 | The quotation of strings by `\'' and `"' can be used | |
607 | to prevent all or some of the remaining substitutions. | |
608 | Strings enclosed in `\'' are prevented any further interpretation. | |
609 | Strings enclosed in `"' may be expanded as described below. | |
610 | .Pp | |
611 | In both cases the resulting text becomes (all or part of) a single word; | |
612 | only in one special case (see | |
613 | .Em Command Substitition | |
614 | below) does a `"' quoted string yield parts of more than one word; | |
615 | `\'' quoted strings never do. | |
616 | .Ss Alias substitution | |
617 | The shell maintains a list of aliases which can be established, displayed | |
618 | and modified by the | |
619 | .Ar alias | |
620 | and | |
621 | .Ar unalias | |
622 | commands. | |
623 | After a command line is scanned, it is parsed into distinct commands and | |
624 | the first word of each command, left-to-right, is checked to see if it | |
625 | has an alias. | |
626 | If it does, then the text which is the alias for that command is reread | |
627 | with the history mechanism available | |
628 | as though that command were the previous input line. | |
629 | The resulting words replace the | |
630 | command and argument list. | |
631 | If no reference is made to the history list, then the argument list is | |
632 | left unchanged. | |
633 | .Pp | |
634 | Thus if the alias for `ls' is `ls \-l' the command `ls /usr' would map to | |
635 | `ls \-l /usr', the argument list here being undisturbed. | |
636 | Similarly if the alias for `lookup' was `grep !\*(ua /etc/passwd' then | |
637 | `lookup bill' would map to `grep bill /etc/passwd'. | |
638 | .Pp | |
639 | If an alias is found, the word transformation of the input text | |
640 | is performed and the aliasing process begins again on the reformed input line. | |
641 | Looping is prevented if the first word of the new text is the same as the old | |
642 | by flagging it to prevent further aliasing. | |
643 | Other loops are detected and cause an error. | |
644 | .Pp | |
645 | Note that the mechanism allows aliases to introduce parser metasyntax. | |
646 | Thus we can `alias print \'pr \e!* \&| lpr\'' to make a command which | |
647 | .Ar pr \'s | |
648 | its arguments to the line printer. | |
649 | .Ss Variable substitution | |
650 | The shell maintains a set of variables, each of which has as value a list | |
651 | of zero or more words. | |
652 | Some of these variables are set by the shell or referred to by it. | |
653 | For instance, the | |
654 | .Ar argv | |
655 | variable is an image of the shell's argument list, and words of this | |
656 | variable's value are referred to in special ways. | |
657 | .Pp | |
658 | The values of variables may be displayed and changed by using the | |
659 | .Ar set | |
660 | and | |
661 | .Ar unset | |
662 | commands. | |
663 | Of the variables referred to by the shell a number are toggles; | |
664 | the shell does not care what their value is, | |
665 | only whether they are set or not. | |
666 | For instance, the | |
667 | .Ar verbose | |
668 | variable is a toggle which causes command input to be echoed. | |
669 | The setting of this variable results from the | |
670 | .Fl v | |
671 | command line option. | |
672 | .Pp | |
673 | Other operations treat variables numerically. | |
674 | The `@' command permits numeric calculations to be performed and the result | |
675 | assigned to a variable. | |
676 | Variable values are, however, always represented as (zero or more) strings. | |
677 | For the purposes of numeric operations, the null string is considered to be | |
678 | zero, and the second and subsequent words of multiword values are ignored. | |
679 | .Pp | |
680 | After the input line is aliased and parsed, and before each command | |
681 | is executed, variable substitution | |
682 | is performed keyed by `$' characters. | |
683 | This expansion can be prevented by preceding the `$' with a `\e' except | |
684 | within `"'s where it | |
685 | .Em always | |
686 | occurs, and within `\''s where it | |
687 | .Em never | |
688 | occurs. | |
689 | Strings quoted by `\*(ga' are interpreted later (see | |
690 | .Nm "Command substitution" | |
691 | below) so `$' substitution does not occur there until later, if at all. | |
692 | A `$' is passed unchanged if followed by a blank, tab, or end-of-line. | |
693 | .Pp | |
694 | Input/output redirections are recognized before variable expansion, | |
695 | and are variable expanded separately. | |
696 | Otherwise, the command name and entire argument list are expanded together. | |
697 | It is thus possible for the first (command) word to this point to generate | |
698 | more than one word, the first of which becomes the command name, | |
699 | and the rest of which become arguments. | |
700 | .Pp | |
701 | Unless enclosed in `"' or given the `:q' modifier the results of variable | |
702 | substitution may eventually be command and filename substituted. | |
703 | Within `"', a variable whose value consists of multiple words expands to a | |
704 | (portion of) a single word, with the words of the variables value | |
705 | separated by blanks. | |
706 | When the `:q' modifier is applied to a substitution | |
707 | the variable will expand to multiple words with each word separated | |
708 | by a blank and quoted to prevent later command or filename substitution. | |
709 | .Pp | |
710 | The following metasequences are provided for introducing variable values into | |
711 | the shell input. | |
712 | Except as noted, it is an error to reference a variable which is not set. | |
713 | .Pp | |
714 | .Bl -tag -width Ds -compact -offset indent | |
715 | .It $name | |
716 | .It ${name} | |
717 | Are replaced by the words of the value of variable | |
718 | .Ar name , | |
719 | each separated by a blank. | |
720 | Braces insulate | |
721 | .Ar name | |
722 | from following characters which would otherwise be part of it. | |
723 | Shell variables have names consisting of up to 20 letters and digits | |
724 | starting with a letter. The underscore character is considered a letter. | |
725 | .br | |
726 | If | |
727 | .Ar name | |
728 | is not a shell variable, but is set in the environment, then | |
729 | that value is returned (but | |
730 | .Nm : | |
731 | modifiers and the other forms | |
732 | given below are not available in this case). | |
733 | .It $name Ns Op selector | |
734 | .It ${name Ns Op selector Ns } | |
735 | May be used to select only some of the words from the value of | |
736 | .Ar name . | |
737 | The selector is subjected to `$' substitution and may consist of a single | |
738 | number or two numbers separated by a `\-'. | |
739 | The first word of a variables value is numbered `1'. | |
740 | If the first number of a range is omitted it defaults to `1'. | |
741 | If the last member of a range is omitted it defaults to `$#name'. | |
742 | The selector `*' selects all words. | |
743 | It is not an error for a range to be empty if the second argument is omitted | |
744 | or in range. | |
745 | .It $#name | |
746 | .It ${#name} | |
747 | Gives the number of words in the variable. | |
748 | This is useful for later use in a | |
749 | `$argv[selector]'. | |
750 | .It $0 | |
751 | Substitutes the name of the file from which command input is being read. | |
752 | An error occurs if the name is not known. | |
753 | .It $number | |
754 | .It ${number} | |
755 | Equivalent to | |
756 | `$argv[number]'. | |
757 | .It $* | |
758 | Equivalent to | |
759 | `$argv[*]'. | |
760 | The modifiers `:e', `:h', `:t', `:r', `:q' and `:x' may be applied to | |
761 | the substitutions above as may `:gh', `:gt' and `:gr'. | |
762 | If braces `{' '}' appear in the command form then the modifiers | |
763 | must appear within the braces. | |
764 | The current implementation allows only one `:' modifier on each `$' expansion. | |
765 | .El | |
766 | .Pp | |
767 | The following substitutions may not be modified with `:' modifiers. | |
768 | .Bl -tag -width Ds -compact -offset indent | |
769 | .It $?name | |
770 | .It ${?name} | |
771 | Substitutes the string `1' if name is set, `0' if it is not. | |
772 | .It $?0 | |
773 | Substitutes `1' if the current input filename is known, `0' if it is not. | |
774 | .It $$ | |
775 | Substitute the (decimal) process number of the (parent) shell. | |
776 | .It $< | |
777 | Substitutes a line from the standard | |
778 | input, with no further interpretation thereafter. It can be used | |
779 | to read from the keyboard in a shell script. | |
780 | .El | |
781 | .Ss Command and filename substitution | |
782 | The remaining substitutions, command and filename substitution, | |
783 | are applied selectively to the arguments of builtin commands. | |
784 | This means that portions of expressions which are not evaluated are | |
785 | not subjected to these expansions. | |
786 | For commands which are not internal to the shell, the command | |
787 | name is substituted separately from the argument list. | |
788 | This occurs very late, | |
789 | after input-output redirection is performed, and in a child | |
790 | of the main shell. | |
791 | .Ss Command substitution | |
792 | Command substitution is indicated by a command enclosed in `\*(ga'. | |
793 | The output from such a command is normally broken into separate words | |
794 | at blanks, tabs and newlines, with null words being discarded, | |
795 | this text then replacing the original string. | |
796 | Within `"'s, only newlines force new words; blanks and tabs are preserved. | |
797 | .Pp | |
798 | In any case, the single final newline does not force a new word. | |
799 | Note that it is thus possible for a command substitution to yield | |
800 | only part of a word, even if the command outputs a complete line. | |
801 | .Ss Filename substitution | |
802 | If a word contains any of the characters `*', `?', `[' or `{' | |
803 | or begins with the character `~', then that word is a candidate for | |
804 | filename substitution, also known as `globbing'. | |
805 | This word is then regarded as a pattern, and replaced with an alphabetically | |
806 | sorted list of file names which match the pattern. | |
807 | In a list of words specifying filename substitution it is an error for | |
808 | no pattern to match an existing file name, but it is not required | |
809 | for each pattern to match. | |
810 | Only the metacharacters `*', `?' and `[' imply pattern matching, | |
811 | the characters `~' and `{' being more akin to abbreviations. | |
812 | .Pp | |
813 | In matching filenames, the character `.' at the beginning of a filename | |
814 | or immediately following a `/', as well as the character `/' must | |
815 | be matched explicitly. | |
816 | The character `*' matches any string of characters, including the null | |
817 | string. | |
818 | The character `?' matches any single character. | |
819 | The sequence | |
820 | .Sq Op ... | |
821 | matches any one of the characters enclosed. | |
822 | Within | |
823 | .Sq Op ... , | |
824 | a pair of characters separated by `\-' matches any character lexically between | |
825 | the two. | |
826 | .Pp | |
827 | The character `~' at the beginning of a filename is used to refer to home | |
828 | directories. | |
829 | Standing alone, i.e. `~' it expands to the invokers home directory as reflected | |
830 | in the value of the variable | |
831 | .Ar home . | |
832 | When followed by a name consisting of letters, digits and `\-' characters | |
833 | the shell searches for a user with that name and substitutes their | |
834 | home directory; thus `~ken' might expand to `/usr/ken' and `~ken/chmach' | |
835 | to `/usr/ken/chmach'. | |
836 | If the character `~' is followed by a character other than a letter or `/' | |
837 | or appears not at the beginning of a word, | |
838 | it is left undisturbed. | |
839 | .Pp | |
840 | The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'. | |
841 | Left to right order is preserved, with results of matches being sorted | |
842 | separately at a low level to preserve this order. | |
843 | This construct may be nested. | |
844 | Thus `~source/s1/{oldls,ls}.c' expands to | |
845 | `/usr/source/s1/oldls.c /usr/source/s1/ls.c' | |
846 | whether or not these files exist without any chance of error | |
847 | if the home directory for `source' is `/usr/source'. | |
848 | Similarly `../{memo,*box}' might expand to `../memo ../box ../mbox'. | |
849 | (Note that `memo' was not sorted with the results of matching `*box'.) | |
850 | As a special case `{', `}' and `{}' are passed undisturbed. | |
851 | .Ss Input/output | |
852 | The standard input and standard output of a command may be redirected | |
853 | with the following syntax: | |
854 | .Pp | |
855 | .Bl -tag -width Ds -compact -offset indent | |
856 | .It < name | |
857 | Open file | |
858 | .Ar name | |
859 | (which is first variable, command and filename expanded) as the standard | |
860 | input. | |
861 | .It << word | |
862 | Read the shell input up to a line which is identical to | |
863 | .Ar word . | |
864 | .Ar Word | |
865 | is not subjected to variable, filename or command substitution, | |
866 | and each input line is compared to | |
867 | .Ar word | |
868 | before any substitutions are done on this input line. | |
869 | Unless a quoting `\e', `"', `\*(aa' or `\*(ga' appears in | |
870 | .Ar word | |
871 | variable and command substitution is performed on the intervening lines, | |
872 | allowing `\e' to quote `$', `\e' and `\*(ga'. | |
873 | Commands which are substituted have all blanks, tabs, and newlines | |
874 | preserved, except for the final newline which is dropped. | |
875 | The resultant text is placed in an anonymous temporary file which | |
876 | is given to the command as standard input. | |
877 | .It > name | |
878 | .It >! name | |
879 | .It >& name | |
880 | .It >&! name | |
881 | The file | |
882 | .Ar name | |
883 | is used as standard output. | |
884 | If the file does not exist then it is created; | |
885 | if the file exists, its is truncated, its previous contents being lost. | |
886 | .Pp | |
887 | If the variable | |
888 | .Ar noclobber | |
889 | is set, then the file must not exist or be a character special file (e.g. a | |
890 | terminal or `/dev/null') or an error results. | |
891 | This helps prevent accidental destruction of files. | |
892 | In this case the `!' forms can be used and suppress this check. | |
893 | .Pp | |
894 | The forms involving `&' route the diagnostic output into the specified | |
895 | file as well as the standard output. | |
896 | .Ar Name | |
897 | is expanded in the same way as `<' input filenames are. | |
898 | .It >> name | |
899 | .It >>& name | |
900 | .It >>! name | |
901 | .It >>&! name | |
902 | Uses file | |
903 | .Ar name | |
904 | as standard output like `>' but places output at the end of the file. | |
905 | If the variable | |
906 | .Ar noclobber | |
907 | is set, then it is an error for the file not to exist unless | |
908 | one of the `!' forms is given. | |
909 | Otherwise similar to `>'. | |
910 | .El | |
911 | .Pp | |
912 | A command receives the environment in which the shell was | |
913 | invoked as modified by the input-output parameters and | |
914 | the presence of the command in a pipeline. | |
915 | Thus, unlike some previous shells, commands run from a file of shell commands | |
916 | have no access to the text of the commands by default; rather | |
917 | they receive the original standard input of the shell. | |
918 | The `<<' mechanism should be used to present inline data. | |
919 | This permits shell command scripts to function as components of pipelines | |
920 | and allows the shell to block read its input. | |
921 | Note that the default standard input for a command run detached is | |
922 | .Ar not | |
923 | modified to be the empty file | |
924 | .Pa /dev/null ; | |
925 | rather the standard input | |
926 | remains as the original standard input of the shell. If this is a terminal | |
927 | and if the process attempts to read from the terminal, then the process | |
928 | will block and the user will be notified (see | |
929 | .Sx Jobs | |
930 | above). | |
931 | .Pp | |
932 | Diagnostic output may be directed through a pipe with the standard output. | |
933 | Simply use the form `\&|&' rather than just `\&|'. | |
934 | .Ss Expressions | |
935 | A number of the builtin commands (to be described subsequently) | |
936 | take expressions, in which the operators are similar to those of C, with | |
937 | the same precedence. | |
938 | These expressions appear in the | |
939 | .Nm @, | |
940 | .Ar exit , | |
941 | .Ar if , | |
942 | and | |
943 | .Ar while | |
944 | commands. | |
945 | The following operators are available: | |
946 | .Bd -ragged -offset indent | |
947 | \&|\&| && \&| *(ua & == != =~ !~ <= >= | |
948 | < > << >> + \- * / % ! ~ ( ) | |
949 | .Ed | |
950 | .Pp | |
951 | Here the precedence increases to the right, | |
952 | `==' `!=' `=~' and `!~', `<=' `>=' `<' and `>', `<<' and `>>', `+' and `\-', | |
953 | `*' `/' and `%' being, in groups, at the same level. | |
954 | The `==' `!=' `=~' and `!~' operators compare their arguments as strings; | |
955 | all others operate on numbers. | |
956 | The operators `=~' and `!~' are like `!=' and `==' except that the right | |
957 | hand side is a | |
958 | .Ar pattern | |
959 | (containing, e.g. `*'s, `?'s and instances of | |
960 | `[...]' | |
961 | against which the left hand operand is matched. This reduces the | |
962 | need for use of the | |
963 | .Ar switch | |
964 | statement in shell scripts when all that is really needed is pattern matching. | |
965 | .Pp | |
966 | Strings which begin with `0' are considered octal numbers. | |
967 | Null or missing arguments are considered `0'. | |
968 | The result of all expressions are strings, | |
969 | which represent decimal numbers. | |
970 | It is important to note that no two components of an expression can appear | |
971 | in the same word; except when adjacent to components of expressions which | |
972 | are syntactically significant to the parser (`&' `\&|' `<' `>' `(' `)') | |
973 | they should be surrounded by spaces. | |
974 | .Pp | |
975 | Also available in expressions as primitive operands are command executions | |
976 | enclosed in `{' and `}' | |
977 | and file enquiries of the form | |
978 | .Fl l | |
979 | .Ar name | |
980 | where | |
981 | .Ic l | |
982 | is one of: | |
983 | .Bd -ragged -offset indent | |
984 | r read access | |
985 | w write access | |
986 | x execute access | |
987 | e existence | |
988 | o ownership | |
989 | z zero size | |
990 | f plain file | |
991 | d directory | |
992 | .Ed | |
993 | .Pp | |
994 | The specified name is command and filename expanded and then tested | |
995 | to see if it has the specified relationship to the real user. | |
996 | If the file does not exist or is inaccessible then all enquiries return | |
997 | false, i.e. `0'. | |
998 | Command executions succeed, returning true, i.e. `1', | |
999 | if the command exits with status 0, otherwise they fail, returning | |
1000 | false, i.e. `0'. | |
1001 | If more detailed status information is required then the command | |
1002 | should be executed outside of an expression and the variable | |
1003 | .Ar status | |
1004 | examined. | |
1005 | .Ss Control flow | |
1006 | The shell contains a number of commands which can be used to regulate the | |
1007 | flow of control in command files (shell scripts) and | |
1008 | (in limited but useful ways) from terminal input. | |
1009 | These commands all operate by forcing the shell to reread or skip in its | |
1010 | input and, due to the implementation, restrict the placement of some | |
1011 | of the commands. | |
1012 | .Pp | |
1013 | The | |
1014 | .Ic foreach , | |
1015 | .Ic switch , | |
1016 | and | |
1017 | .Ic while | |
1018 | statements, as well as the | |
1019 | .Ic if\-then\-else | |
1020 | form of the | |
1021 | .Ic if | |
1022 | statement require that the major keywords appear in a single simple command | |
1023 | on an input line as shown below. | |
1024 | .Pp | |
1025 | If the shell's input is not seekable, | |
1026 | the shell buffers up input whenever a loop is being read | |
1027 | and performs seeks in this internal buffer to accomplish the rereading | |
1028 | implied by the loop. | |
1029 | (To the extent that this allows, backward goto's will succeed on | |
1030 | non-seekable inputs.) | |
1031 | .Ss Builtin commands | |
1032 | Builtin commands are executed within the shell. | |
1033 | If a builtin command occurs as any component of a pipeline | |
1034 | except the last then it is executed in a subshell. | |
1035 | .Pp | |
1036 | .Bl -tag -width Ds -compact -offset indent | |
1037 | .It Ic alias | |
1038 | .It Ic alias Ar name | |
1039 | .It Ic alias Ar name wordlist | |
1040 | The first form prints all aliases. | |
1041 | The second form prints the alias for name. | |
1042 | The final form assigns the specified | |
1043 | .Ar wordlist | |
1044 | as the alias of | |
1045 | .Ar name ; | |
1046 | .Ar wordlist | |
1047 | is command and filename substituted. | |
1048 | .Ar Name | |
1049 | is not allowed to be | |
1050 | .Ar alias | |
1051 | or | |
1052 | .Ar unalias . | |
1053 | .Pp | |
1054 | .It Ic alloc | |
1055 | Shows the amount of dynamic memory acquired, broken down into used and | |
1056 | free memory. | |
1057 | With an argument shows the number of free and used blocks in each size | |
1058 | category. The categories start at size 8 and double at each step. | |
1059 | This command's output may vary across system types, since | |
1060 | systems other than the VAX may use a different memory allocator. | |
1061 | .Pp | |
1062 | .It Ic bg | |
1063 | .It Ic bg \&% Ns Ar job ... | |
1064 | Puts the current or specified jobs into the background, continuing them | |
1065 | if they were stopped. | |
1066 | .Pp | |
1067 | .It Ic break | |
1068 | Causes execution to resume after the | |
1069 | .Ic end | |
1070 | of the nearest enclosing | |
1071 | .Ic foreach | |
1072 | or | |
1073 | .Ic while . | |
1074 | The remaining commands on the current line are executed. | |
1075 | Multi-level breaks are thus possible by writing them all on one line. | |
1076 | .Pp | |
1077 | .It Ic breaksw | |
1078 | Causes a break from a | |
1079 | .Ic switch , | |
1080 | resuming after the | |
1081 | .Ic endsw . | |
1082 | .Pp | |
1083 | .It Ic case Ar label : | |
1084 | A label in a | |
1085 | .Ic switch | |
1086 | statement as discussed below. | |
1087 | .Pp | |
1088 | .It Ic cd | |
1089 | .It Ic cd Ar name | |
1090 | .It Ic chdir | |
1091 | .It Ic chdir Ar name | |
1092 | Change the shell's working directory to directory | |
1093 | .Ar name . | |
1094 | If no argument is given then change to the home directory of the user. | |
1095 | If | |
1096 | .Ar name | |
1097 | is not found as a subdirectory of the current directory (and does not begin | |
1098 | with `/', `./' or `../'), then each | |
1099 | component of the variable | |
1100 | .Ic cdpath | |
1101 | is checked to see if it has a subdirectory | |
1102 | .Ar name . | |
1103 | Finally, if all else fails but | |
1104 | .Ar name | |
1105 | is a shell variable whose value begins with `/', then this | |
1106 | is tried to see if it is a directory. | |
1107 | .Pp | |
1108 | .It Ic continue | |
1109 | Continue execution of the nearest enclosing | |
1110 | .Ic while | |
1111 | or | |
1112 | .Ic foreach . | |
1113 | The rest of the commands on the current line are executed. | |
1114 | .Pp | |
1115 | .It Ic default : | |
1116 | Labels the default case in a | |
1117 | .Ic switch | |
1118 | statement. | |
1119 | The default should come after all | |
1120 | .Ic case | |
1121 | labels. | |
1122 | .Pp | |
1123 | .It Ic dirs | |
1124 | Prints the directory stack; the top of the stack is at the left, | |
1125 | the first directory in the stack being the current directory. | |
1126 | .Pp | |
1127 | .It Ic echo Ar wordlist | |
1128 | .It Ic echo Fl n Ar wordlist | |
1129 | The specified words are written to the shells standard output, separated | |
1130 | by spaces, and terminated with a newline unless the | |
1131 | .Fl n | |
1132 | option is specified. | |
1133 | .Pp | |
1134 | .It Ic else | |
1135 | .It Ic end | |
1136 | .It Ic endif | |
1137 | .It Ic endsw | |
1138 | See the description of the | |
1139 | .Ic foreach , | |
1140 | .Ic if , | |
1141 | .Ic switch , | |
1142 | and | |
1143 | .Ic while | |
1144 | statements below. | |
1145 | .Pp | |
1146 | .It Ic eval Ar arg ... | |
1147 | (As in | |
1148 | .Xr sh 1 . ) | |
1149 | The arguments are read as input to the shell and the resulting | |
1150 | command(s) executed in the context of the current shell. | |
1151 | This is usually used to execute commands | |
1152 | generated as the result of command or variable substitution, since | |
1153 | parsing occurs before these substitutions. See | |
1154 | .Xr tset 1 | |
1155 | for an example of using | |
1156 | .Ic eval . | |
1157 | .Pp | |
1158 | .It Ic exec Ar command | |
1159 | The specified command is executed in place of the current shell. | |
1160 | .Pp | |
1161 | .It Ic exit | |
1162 | .It Ic exit Ar (expr ) | |
1163 | The shell exits either with the value of the | |
1164 | .Ic status | |
1165 | variable (first form) or with the value of the specified | |
1166 | .Ic expr | |
1167 | (second form). | |
1168 | .Pp | |
1169 | .It Ic fg | |
1170 | .It Ic fg \&% Ar job ... | |
1171 | Brings the current or specified jobs into the foreground, continuing them if | |
1172 | they were stopped. | |
1173 | .Pp | |
1174 | .It Ic foreach Ar name (wordlist) | |
1175 | .It ... | |
1176 | .It Ic end | |
1177 | The variable | |
1178 | .Ic name | |
1179 | is successively set to each member of | |
1180 | .Ic wordlist | |
1181 | and the sequence of commands between this command and the matching | |
1182 | .Ic end | |
1183 | are executed. | |
1184 | (Both | |
1185 | .Ic foreach | |
1186 | and | |
1187 | .Ic end | |
1188 | must appear alone on separate lines.) | |
1189 | The builtin command | |
1190 | .Ic continue | |
1191 | may be used to continue the loop prematurely and the builtin | |
1192 | command | |
1193 | .Ic break | |
1194 | to terminate it prematurely. | |
1195 | When this command is read from the terminal, the loop is read up once | |
1196 | prompting with `?' before any statements in the loop are executed. | |
1197 | If you make a mistake typing in a loop at the terminal you can rub it out. | |
1198 | .Pp | |
1199 | .It Ic glob Ar wordlist | |
1200 | Like | |
1201 | .Ic echo | |
1202 | but no `\e' escapes are recognized and words are delimited | |
1203 | by null characters in the output. | |
1204 | Useful for programs which wish to use the shell to filename expand a list | |
1205 | of words. | |
1206 | .Pp | |
1207 | .It Ic goto Ar word | |
1208 | The specified | |
1209 | .Ic word | |
1210 | is filename and command expanded to yield a string of the form `label'. | |
1211 | The shell rewinds its input as much as possible | |
1212 | and searches for a line of the form `label:' | |
1213 | possibly preceded by blanks or tabs. | |
1214 | Execution continues after the specified line. | |
1215 | .Pp | |
1216 | .It Ic hashstat | |
1217 | Print a statistics line indicating how effective the internal hash | |
1218 | table has been at locating commands (and avoiding | |
1219 | .Ic exec Ns \'s ) . | |
1220 | An | |
1221 | .Ic exec | |
1222 | is attempted for each component of the | |
1223 | .Em path | |
1224 | where the hash function indicates a possible hit, and in each component | |
1225 | which does not begin with a `/'. | |
1226 | .Pp | |
1227 | .It Ic history | |
1228 | .It Ic history Ar n | |
1229 | .It Ic history Fl r Ar n | |
1230 | .It Ic history Fl h Ar n | |
1231 | Displays the history event list; if | |
1232 | .Ar n | |
1233 | is given only the | |
1234 | .Ar n | |
1235 | most recent events are printed. | |
1236 | The | |
1237 | .Fl r | |
1238 | option reverses the order of printout to be most recent first | |
1239 | rather than oldest first. | |
1240 | The | |
1241 | .Fl h | |
1242 | option causes the history list to be printed without leading numbers. | |
1243 | This is used to produce files suitable for sourceing using the \-h | |
1244 | option to | |
1245 | .Ic source . | |
1246 | .Pp | |
1247 | .It Ic if Pq Ar expr No command | |
1248 | If the specified expression evaluates true, then the single | |
1249 | .Ar command | |
1250 | with arguments is executed. | |
1251 | Variable substitution on | |
1252 | .Ar command | |
1253 | happens early, at the same | |
1254 | time it does for the rest of the | |
1255 | .Ic if | |
1256 | command. | |
1257 | .Ar Command | |
1258 | must be a simple command, not | |
1259 | a pipeline, a command list, or a parenthesized command list. | |
1260 | Input/output redirection occurs even if | |
1261 | .Ar expr | |
1262 | is false, when command is | |
1263 | .Sy not | |
1264 | executed (this is a bug). | |
1265 | .Pp | |
1266 | .It Ic if ( Ar expr ) Ic then | |
1267 | .It ... | |
1268 | .It Ic else if ( Ar expr2 ) Ic then | |
1269 | .It ... | |
1270 | .It Ic else | |
1271 | .It ... | |
1272 | .It Ic endif | |
1273 | If the specified | |
1274 | .Ar expr | |
1275 | is true then the commands to the first | |
1276 | .Ic else | |
1277 | are executed; otherwise if | |
1278 | .Ar expr2 | |
1279 | is true then the commands to the | |
1280 | second | |
1281 | .Ic else | |
1282 | are executed, etc. | |
1283 | Any number of | |
1284 | .Ic else-if | |
1285 | pairs are possible; only one | |
1286 | .Ic endif | |
1287 | is needed. | |
1288 | The | |
1289 | .Ic else | |
1290 | part is likewise optional. | |
1291 | (The words | |
1292 | .Ic else | |
1293 | and | |
1294 | .Ic endif | |
1295 | must appear at the beginning of input lines; | |
1296 | the | |
1297 | .Ic if | |
1298 | must appear alone on its input line or after an | |
1299 | .Ic else . ) | |
1300 | .Pp | |
1301 | .It Ic jobs | |
1302 | .It Ic jobs Fl l | |
1303 | Lists the active jobs; given the | |
1304 | .Fl l | |
1305 | options lists process id's in addition to the normal information. | |
1306 | .Pp | |
1307 | .It Ic kill % Ar job | |
1308 | .It Ic kill Ar pid | |
1309 | .It Ic kill Fl sig Ar pid ... | |
1310 | .It Ic kill Fl l | |
1311 | Sends either the TERM (terminate) signal or the | |
1312 | specified signal to the specified jobs or processes. | |
1313 | Signals are either given by number or by names (as given in | |
1314 | .Pa /usr/include/signal.h, | |
1315 | stripped of the prefix ``SIG''). | |
1316 | The signal names are listed by ``kill \-l''. | |
1317 | There is no default, saying just `kill' does not | |
1318 | send a signal to the current job. | |
1319 | If the signal being sent is TERM (terminate) or HUP (hangup), | |
1320 | then the job or process will be sent a CONT (continue) signal as well. | |
1321 | .Pp | |
1322 | .It Ic limit | |
1323 | .It Ic limit Ar resource | |
1324 | .It Ic limit Ar resource maximum-use | |
1325 | .It Ic limit Fl h | |
1326 | .It Ic limit Fl h Ar resource | |
1327 | .It Ic limit Fl h Ar resource maximum-use | |
1328 | Limits the consumption by the current process and each process | |
1329 | it creates to not individually exceed | |
1330 | .Ar maximum-use | |
1331 | on the | |
1332 | specified | |
1333 | .Ar resource . | |
1334 | If no | |
1335 | .Ar maximum-use | |
1336 | is given, then | |
1337 | the current limit is printed; if no | |
1338 | .Ar resource | |
1339 | is given, then | |
1340 | all limitations are given. If the | |
1341 | .Fl h | |
1342 | flag is given, the hard limits are used instead of the current | |
1343 | limits. The hard limits impose a ceiling on the values of | |
1344 | the current limits. Only the super-user may raise the hard limits, | |
1345 | but a user may lower or raise the current limits within the legal range. | |
1346 | .Pp | |
1347 | Resources controllable currently include | |
1348 | .Ar cputime | |
1349 | (the maximum | |
1350 | number of cpu-seconds to be used by each process), | |
1351 | .Ar filesize | |
1352 | (the largest single file which can be created), | |
1353 | .Ar datasize | |
1354 | (the maximum growth of the data+stack region via | |
1355 | .Xr sbrk 2 | |
1356 | beyond the end of the program text), | |
1357 | .Ar stacksize | |
1358 | (the maximum | |
1359 | size of the automatically-extended stack region), and | |
1360 | .Ar coredumpsize | |
1361 | (the size of the largest core dump that will be created). | |
1362 | .Pp | |
1363 | The | |
1364 | .Ar maximum-use | |
1365 | may be given as a (floating point or integer) | |
1366 | number followed by a scale factor. For all limits other than | |
1367 | .Ar cputime | |
1368 | the default scale is `k' or `kilobytes' (1024 bytes); | |
1369 | a scale factor of `m' or `megabytes' may also be used. | |
1370 | For | |
1371 | .Ar cputime | |
1372 | the default scaling is `seconds', while `m' for minutes | |
1373 | or `h' for hours, or a time of the form `mm:ss' giving minutes | |
1374 | and seconds may be used. | |
1375 | .Pp | |
1376 | For both | |
1377 | .Ar resource | |
1378 | names and scale factors, unambiguous prefixes | |
1379 | of the names suffice. | |
1380 | .Pp | |
1381 | .It Ic login | |
1382 | Terminate a login shell, replacing it with an instance of | |
1383 | .Pa /bin/login. | |
1384 | This is one way to log off, included for compatibility with | |
1385 | .Xr sh 1 . | |
1386 | .Pp | |
1387 | .It Ic logout | |
1388 | Terminate a login shell. | |
1389 | Especially useful if | |
1390 | .Ic ignoreeof | |
1391 | is set. | |
1392 | .Pp | |
1393 | .It Ic nice | |
1394 | .It Ic nice Ar +number | |
1395 | .It Ic nice Ar command | |
1396 | .It Ic nice Ar +number command | |
1397 | The first form sets the | |
1398 | scheduling priority | |
1399 | for this shell to 4. | |
1400 | The second form sets the | |
1401 | priority | |
1402 | to the given | |
1403 | .Ar number . | |
1404 | The final two forms run command at priority 4 and | |
1405 | .Ar number | |
1406 | respectively. | |
1407 | The greater the number, the less cpu the process will get. | |
1408 | The super-user may specify negative priority by using `nice \-number ...'. | |
1409 | Command is always executed in a sub-shell, and the restrictions | |
1410 | placed on commands in simple | |
1411 | .Ic if | |
1412 | statements apply. | |
1413 | .Pp | |
1414 | .It Ic nohup | |
1415 | .It Ic nohup Ar command | |
1416 | The first form can be used in shell scripts to cause hangups to be | |
1417 | ignored for the remainder of the script. | |
1418 | The second form causes the specified command to be run with hangups | |
1419 | ignored. | |
1420 | All processes detached with `&' are effectively | |
1421 | .Ic nohup Ns \'ed . | |
1422 | .Pp | |
1423 | .It Ic notify | |
1424 | .It Ic notify % Ar job ... | |
1425 | Causes the shell to notify the user asynchronously when the status of the | |
1426 | current or specified jobs changes; normally notification is presented | |
1427 | before a prompt. This is automatic if the shell variable | |
1428 | .Ic notify | |
1429 | is set. | |
1430 | .Pp | |
1431 | .It Ic onintr | |
1432 | .It Ic onintr Fl | |
1433 | .It Ic onintr Ar label | |
1434 | Control the action of the shell on interrupts. | |
1435 | The first form restores the default action of the shell on interrupts | |
1436 | which is to terminate shell scripts or to return to the terminal command | |
1437 | input level. | |
1438 | The second form `onintr \-' causes all interrupts to be ignored. | |
1439 | The final form causes the shell to execute a `goto label' when | |
1440 | an interrupt is received or a child process terminates because | |
1441 | it was interrupted. | |
1442 | .Pp | |
1443 | In any case, if the shell is running detached and interrupts are | |
1444 | being ignored, all forms of | |
1445 | .Ic onintr | |
1446 | have no meaning and interrupts | |
1447 | continue to be ignored by the shell and all invoked commands. | |
1448 | .Pp | |
1449 | .It Ic popd | |
1450 | .It Ic popd Ar +n | |
1451 | Pops the directory stack, returning to the new top directory. | |
1452 | With an argument | |
1453 | .Ns \`+ Ar n Ns \' | |
1454 | discards the | |
1455 | .Ar n Ns \'th | |
1456 | entry in the stack. | |
1457 | The elements of the directory stack are numbered from 0 starting at the top. | |
1458 | .Pp | |
1459 | .It Ic pushd | |
1460 | .It Ic pushd Ar name | |
1461 | .It Ic pushd Ar n | |
1462 | With no arguments, | |
1463 | .Ic pushd | |
1464 | exchanges the top two elements of the directory stack. | |
1465 | Given a | |
1466 | .Ar name | |
1467 | argument, | |
1468 | .Ic pushd | |
1469 | changes to the new directory (ala | |
1470 | .Ic cd ) | |
1471 | and pushes the old current working directory | |
1472 | (as in | |
1473 | .Ic csw ) | |
1474 | onto the directory stack. | |
1475 | With a numeric argument, rotates the | |
1476 | .Ar n Ns \'th | |
1477 | argument of the directory | |
1478 | stack around to be the top element and changes to it. The members | |
1479 | of the directory stack are numbered from the top starting at 0. | |
1480 | .Pp | |
1481 | .It Ic rehash | |
1482 | Causes the internal hash table of the contents of the directories in | |
1483 | the | |
1484 | .Ic path | |
1485 | variable to be recomputed. This is needed if new commands are added | |
1486 | to directories in the | |
1487 | .Ic path | |
1488 | while you are logged in. This should only be necessary if you add | |
1489 | commands to one of your own directories, or if a systems programmer | |
1490 | changes the contents of one of the system directories. | |
1491 | .Pp | |
1492 | .It Ic repeat Ar count command | |
1493 | The specified | |
1494 | .Ar command | |
1495 | which is subject to the same restrictions | |
1496 | as the | |
1497 | .Ar command | |
1498 | in the one line | |
1499 | .Ic if | |
1500 | statement above, | |
1501 | is executed | |
1502 | .Ar count | |
1503 | times. | |
1504 | I/O redirections occur exactly once, even if | |
1505 | .Ar count | |
1506 | is 0. | |
1507 | .Pp | |
1508 | .It Ic set | |
1509 | .It Ic set Ar name | |
1510 | .It Ic set Ar name Ns =word | |
1511 | .It Ic set Ar name[index] Ns =word | |
1512 | .It Ic set Ar name Ns =(wordlist) | |
1513 | The first form of the command shows the value of all shell variables. | |
1514 | Variables which have other than a single word as value print as a parenthesized | |
1515 | word list. | |
1516 | The second form sets | |
1517 | .Ic name | |
1518 | to the null string. | |
1519 | The third form sets | |
1520 | .Ic name | |
1521 | to the single | |
1522 | .Ic word . | |
1523 | The fourth form sets | |
1524 | the | |
1525 | .Ar index Ns 'th | |
1526 | component of name to word; | |
1527 | this component must already exist. | |
1528 | The final form sets | |
1529 | .Ar name | |
1530 | to the list of words in | |
1531 | .Ar wordlist . | |
1532 | In all cases the value is command and filename expanded. | |
1533 | .Pp | |
1534 | These arguments may be repeated to set multiple values in a single set command. | |
1535 | Note however, that variable expansion happens for all arguments before any | |
1536 | setting occurs. | |
1537 | .Pp | |
1538 | .It Ic setenv | |
1539 | .It Ic setenv Ar name value | |
1540 | .It Ic setenv Ar name | |
1541 | The first form lists all current environment variables. | |
1542 | The last form sets the value of environment variable | |
1543 | .Ar name | |
1544 | to be | |
1545 | .Ar value , | |
1546 | a single string. The second form sets | |
1547 | .Ar name | |
1548 | to an empty string. | |
1549 | The most commonly used environment variable | |
1550 | .Ev USER , | |
1551 | .Ev TERM , | |
1552 | and | |
1553 | .Ev PATH | |
1554 | are automatically imported to and exported from the | |
1555 | .Nm csh | |
1556 | variables | |
1557 | .Ar user , | |
1558 | .Op Ar term , | |
1559 | and | |
1560 | .Ar path ; | |
1561 | there is no need to use | |
1562 | .Ic setenv | |
1563 | for these. | |
1564 | .Pp | |
1565 | .It Ic shift | |
1566 | .It Ic shift Ar variable | |
1567 | The members of | |
1568 | .Ic argv | |
1569 | are shifted to the left, discarding | |
1570 | .Ic argv Bq 1 . | |
1571 | It is an error for | |
1572 | .Ic argv | |
1573 | not to be set or to have less than one word as value. | |
1574 | The second form performs the same function on the specified variable. | |
1575 | .Pp | |
1576 | .It Ic source Ar name | |
1577 | .It Ic source Fl h Ar name | |
1578 | The shell reads commands from | |
1579 | .Ic name . | |
1580 | .Ic Source | |
1581 | commands may be nested; if they are nested too deeply the shell may | |
1582 | run out of file descriptors. | |
1583 | An error in a | |
1584 | .Ic source | |
1585 | at any level terminates all nested | |
1586 | .Ic source | |
1587 | commands. | |
1588 | Normally input during | |
1589 | .Ic source | |
1590 | commands is not placed on the history list; | |
1591 | the \-h option causes the commands to be placed in the | |
1592 | history list without being executed. | |
1593 | .Pp | |
1594 | .It Ic stop | |
1595 | .It Ic stop % Ns Ar job ... | |
1596 | Stops the current or specified job which is executing in the background. | |
1597 | .Pp | |
1598 | .It Ic suspend | |
1599 | Causes the shell to stop in its tracks, much as if it had been sent a stop | |
1600 | signal with | |
1601 | .Ic ^Z . | |
1602 | This is most often used to stop shells started by | |
1603 | .Xr su 1 . | |
1604 | .Pp | |
1605 | .It Ic switch Ar (string) | |
1606 | .It Ic case Ar str1 : | |
1607 | .It \ \ \ \ \&... | |
1608 | .It Ic \ \ \ \ breaksw | |
1609 | .It \ \ \ \ \&... | |
1610 | .It Ic default : | |
1611 | .It \ \ \ \ \&... | |
1612 | .It Ic \ \ \ \ breaksw | |
1613 | .It Ic endsw | |
1614 | Each case label is successively matched, against the specified | |
1615 | .Ar string | |
1616 | which is first command and filename expanded. | |
1617 | The file metacharacters `*', `?' and `[...]' | |
1618 | may be used in the case labels, | |
1619 | which are variable expanded. | |
1620 | If none of the labels match before a `default' label is found, then | |
1621 | the execution begins after the default label. | |
1622 | Each case label and the default label must appear at the beginning of a line. | |
1623 | The command | |
1624 | .Ic breaksw | |
1625 | causes execution to continue after the | |
1626 | .Ic endsw . | |
1627 | Otherwise control may fall through case labels and default labels as in C. | |
1628 | If no label matches and there is no default, execution continues after | |
1629 | the | |
1630 | .Ic endsw . | |
1631 | .Pp | |
1632 | .It Ic time | |
1633 | .It Ic time Ar command | |
1634 | With no argument, a summary of time used by this shell and its children | |
1635 | is printed. | |
1636 | If arguments are given | |
1637 | the specified simple command is timed and a time summary | |
1638 | as described under the | |
1639 | .Ic time | |
1640 | variable is printed. If necessary, an extra shell is created to print the time | |
1641 | statistic when the command completes. | |
1642 | .Pp | |
1643 | .It Ic umask | |
1644 | .It Ic umask Ar value | |
1645 | The file creation mask is displayed (first form) or set to the specified | |
1646 | value (second form). The mask is given in octal. Common values for | |
1647 | the mask are 002 giving all access to the group and read and execute | |
1648 | access to others or 022 giving all access except no write access for | |
1649 | users in the group or others. | |
1650 | .Pp | |
1651 | .It Ic unalias Ar pattern | |
1652 | All aliases whose names match the specified pattern are discarded. | |
1653 | Thus all aliases are removed by `unalias *'. | |
1654 | It is not an error for nothing to be | |
1655 | .Ic unaliased . | |
1656 | .Pp | |
1657 | .It Ic unhash | |
1658 | Use of the internal hash table to speed location of executed programs | |
1659 | is disabled. | |
1660 | .Pp | |
1661 | .It Ic unlimit | |
1662 | .It Ic unlimit Ar resource | |
1663 | .It Ic unlimit Fl h | |
1664 | .It Ic unlimit Fl h Ar resource | |
1665 | Removes the limitation on | |
1666 | .Ar resource . | |
1667 | If no | |
1668 | .Ar resource | |
1669 | is specified, then all | |
1670 | .Ar resource | |
1671 | limitations are removed. If | |
1672 | .Fl h | |
1673 | is given, the corresponding hard limits are removed. Only the | |
1674 | super-user may do this. | |
1675 | .Pp | |
1676 | .It Ic unset Ar pattern | |
1677 | All variables whose names match the specified pattern are removed. | |
1678 | Thus all variables are removed by `unset *'; this has noticeably | |
1679 | distasteful side-effects. | |
1680 | It is not an error for nothing to be | |
1681 | .Ic unset . | |
1682 | .Pp | |
1683 | .It Ic unsetenv Ar pattern | |
1684 | Removes all variables whose name match the specified pattern from the | |
1685 | environment. See also the | |
1686 | .Ic setenv | |
1687 | command above and | |
1688 | .Xr printenv 1 . | |
1689 | .Pp | |
1690 | .It Ic wait | |
1691 | All background jobs are waited for. | |
1692 | It the shell is interactive, then an interrupt can disrupt the wait, | |
1693 | at which time the shell prints names and job numbers of all jobs | |
1694 | known to be outstanding. | |
1695 | .Pp | |
1696 | .It Ic while Ar (expr) | |
1697 | .It \&... | |
1698 | .It Ic end | |
1699 | While the specified expression evaluates non-zero, the commands between | |
1700 | the | |
1701 | .Ic while | |
1702 | and the matching end are evaluated. | |
1703 | .Ic Break | |
1704 | and | |
1705 | .Ic continue | |
1706 | may be used to terminate or continue the loop prematurely. | |
1707 | (The | |
1708 | .Ic while | |
1709 | and | |
1710 | .Ic end | |
1711 | must appear alone on their input lines.) | |
1712 | Prompting occurs here the first time through the loop as for the | |
1713 | .Ic foreach | |
1714 | statement if the input is a terminal. | |
1715 | .Pp | |
1716 | .It Ic % Ar job | |
1717 | Brings the specified job into the foreground. | |
1718 | .Pp | |
1719 | .It Ic % Ar job Ic & | |
1720 | Continues the specified job in the background. | |
1721 | .Pp | |
1722 | .It Ic @ | |
1723 | .It Ic @ Ns Ar name Ns = expr | |
1724 | .It Ic @ Ns Ar name[index] Ns = expr | |
1725 | The first form prints the values of all the shell variables. | |
1726 | The second form sets the specified | |
1727 | .Ar name | |
1728 | to the value of | |
1729 | .Ar expr . | |
1730 | If the expression contains `<', `>', `&' or `' then at least | |
1731 | this part of the expression must be placed within `(' `)'. | |
1732 | The third form assigns the value of | |
1733 | .Ar expr | |
1734 | to the | |
1735 | .Ar index Ns 'th | |
1736 | argument of | |
1737 | .Ar name . | |
1738 | Both | |
1739 | .Ar name | |
1740 | and its | |
1741 | .Ar index Ns 'th | |
1742 | component must already exist. | |
1743 | .El | |
1744 | .Pp | |
1745 | The operators `*=', `+=', etc are available as in C. | |
1746 | The space separating the name from the assignment operator is optional. | |
1747 | Spaces are, however, mandatory in separating components of | |
1748 | .Ar expr | |
1749 | which would otherwise be single words. | |
1750 | .Pp | |
1751 | Special postfix `++' and `\-\-' operators increment and decrement | |
1752 | .Ar name | |
1753 | respectively, i.e. `@ i++'. | |
1754 | .Ss Pre-defined and environment variables | |
1755 | The following variables have special meaning to the shell. | |
1756 | Of these, | |
1757 | .Ar argv , | |
1758 | .Ar cwd, | |
1759 | .Ar home , | |
1760 | .Ar path, | |
1761 | .Ar prompt , | |
1762 | .Ar shell | |
1763 | and | |
1764 | .Ar status | |
1765 | are always set by the shell. | |
1766 | Except for | |
1767 | .Ar cwd | |
1768 | and | |
1769 | .Ar status | |
1770 | this setting occurs only at initialization; | |
1771 | these variables will not then be modified unless this is done | |
1772 | explicitly by the user. | |
1773 | .Pp | |
1774 | This shell copies the environment variable | |
1775 | .Ev USER | |
1776 | into the variable | |
1777 | .Ar user , | |
1778 | .Ev TERM | |
1779 | into | |
1780 | .Ar term , | |
1781 | and | |
1782 | .Ev HOME | |
1783 | into | |
1784 | .Ar home , | |
1785 | and copies these back into the environment whenever the normal | |
1786 | shell variables are reset. | |
1787 | The environment variable | |
1788 | .Ev PATH | |
1789 | is likewise handled; it is not | |
1790 | necessary to worry about its setting other than in the file | |
1791 | .Ar \&.cshrc | |
1792 | as inferior | |
1793 | .Nm csh | |
1794 | processes will import the definition of | |
1795 | .Ar path | |
1796 | from the environment, and re-export it if you then change it. | |
1797 | .Bl -tag -width histchars | |
1798 | .It Ic argv | |
1799 | Set to the arguments to the shell, it is from this variable that | |
1800 | positional parameters are substituted, i.e. `$1' is replaced by | |
1801 | `$argv[1]', | |
1802 | etc. | |
1803 | .It Ic cdpath | |
1804 | Gives a list of alternate directories searched to find subdirectories | |
1805 | in | |
1806 | .Ar chdir | |
1807 | commands. | |
1808 | .It Ic cwd | |
1809 | The full pathname of the current directory. | |
1810 | .It Ic echo | |
1811 | Set when the | |
1812 | .Fl x | |
1813 | command line option is given. | |
1814 | Causes each command and its arguments | |
1815 | to be echoed just before it is executed. | |
1816 | For non-builtin commands all expansions occur before echoing. | |
1817 | Builtin commands are echoed before command and filename substitution, | |
1818 | since these substitutions are then done selectively. | |
1819 | .It Ic filec | |
1820 | Enable file name completion. | |
1821 | .It Ic histchars | |
1822 | Can be given a string value to change the characters used in history | |
1823 | substitution. The first character of its value is used as the | |
1824 | history substitution character, replacing the default character `!'. | |
1825 | The second character of its value replaces the character `\(ua' in | |
1826 | quick substitutions. | |
1827 | .It Ic history | |
1828 | Can be given a numeric value to control the size of the history list. | |
1829 | Any command which has been referenced in this many events will not be | |
1830 | discarded. | |
1831 | Too large values of | |
1832 | .Ar history | |
1833 | may run the shell out of memory. | |
1834 | The last executed command is always saved on the history list. | |
1835 | .It Ic home | |
1836 | The home directory of the invoker, initialized from the environment. | |
1837 | The filename expansion of | |
1838 | .Sq Pa ~ | |
1839 | refers to this variable. | |
1840 | .It Ic ignoreeof | |
1841 | If set the shell ignores | |
1842 | end-of-file from input devices which are terminals. | |
1843 | This prevents shells from accidentally being killed by control-D's. | |
1844 | .It Ic mail | |
1845 | The files where the shell checks for mail. | |
1846 | This is done after each command completion which will result in a prompt, | |
1847 | if a specified interval has elapsed. | |
1848 | The shell says `You have new mail.' | |
1849 | if the file exists with an access time not greater than its modify time. | |
1850 | .Pp | |
1851 | If the first word of the value of | |
1852 | .Ar mail | |
1853 | is numeric it specifies a different mail checking interval, in seconds, | |
1854 | than the default, which is 10 minutes. | |
1855 | .Pp | |
1856 | If multiple mail files are specified, then the shell says | |
1857 | `New mail in | |
1858 | .Ar name Ns ' | |
1859 | when there is mail in the file | |
1860 | .Ar name . | |
1861 | .It Ic noclobber | |
1862 | As described in the section on | |
1863 | .Sx Input/output , | |
1864 | restrictions are placed on output redirection to insure that | |
1865 | files are not accidentally destroyed, and that `>>' redirections | |
1866 | refer to existing files. | |
1867 | .It Ic noglob | |
1868 | If set, filename expansion is inhibited. | |
1869 | This is most useful in shell scripts which are not dealing with filenames, | |
1870 | or after a list of filenames has been obtained and further expansions | |
1871 | are not desirable. | |
1872 | .It Ic nonomatch | |
1873 | If set, it is not an error for a filename expansion to not match any | |
1874 | existing files; rather the primitive pattern is returned. | |
1875 | It is still an error for the primitive pattern to be malformed, i.e. | |
1876 | `echo [' | |
1877 | still gives an error. | |
1878 | .It Ic notify | |
1879 | If set, the shell notifies asynchronously of job completions. The | |
1880 | default is to rather present job completions just before printing | |
1881 | a prompt. | |
1882 | .It Ic path | |
1883 | Each word of the path variable specifies a directory in which | |
1884 | commands are to be sought for execution. | |
1885 | A null word specifies the current directory. | |
1886 | If there is no | |
1887 | .Ar path | |
1888 | variable then only full path names will execute. | |
1889 | The usual search path is `.', `/bin' and `/usr/bin', but this | |
1890 | may vary from system to system. | |
1891 | For the super-user the default search path is `/etc', `/bin' and `/usr/bin'. | |
1892 | A shell which is given neither the | |
1893 | .Fl c | |
1894 | nor the | |
1895 | .Fl t | |
1896 | option will normally hash the contents of the directories in the | |
1897 | .Ar path | |
1898 | variable after reading | |
1899 | .Ar \&.cshrc , | |
1900 | and each time the | |
1901 | .Ar path | |
1902 | variable is reset. If new commands are added to these directories | |
1903 | while the shell is active, it may be necessary to do a | |
1904 | .Ic rehash | |
1905 | or the commands may not be found. | |
1906 | .It Ic prompt | |
1907 | The string which is printed before each command is read from | |
1908 | an interactive terminal input. | |
1909 | If a `!' appears in the string it will be replaced by the current event number | |
1910 | unless a preceding `\e' is given. | |
1911 | Default is `% ', or `# ' for the super-user. | |
1912 | .It Ic savehist | |
1913 | Is given a numeric value to control the number of entries of the | |
1914 | history list that are saved in ~/.history when the user logs out. | |
1915 | Any command which has been referenced in this many events will be saved. | |
1916 | During start up the shell sources ~/.history into the history list | |
1917 | enabling history to be saved across logins. | |
1918 | Too large values of | |
1919 | .Ar savehist | |
1920 | will slow down the shell during start up. | |
1921 | .It Ic shell | |
1922 | The file in which the shell resides. | |
1923 | This is used in forking shells to interpret files which have execute | |
1924 | bits set, but which are not executable by the system. | |
1925 | (See the description of | |
1926 | .Sx Non-builtin Command Execution | |
1927 | below.) | |
1928 | Initialized to the (system-dependent) home of the shell. | |
1929 | .It Ic status | |
1930 | The status returned by the last command. | |
1931 | If it terminated abnormally, then 0200 is added to the status. | |
1932 | Builtin commands which fail return exit status `1', | |
1933 | all other builtin commands set status `0'. | |
1934 | .It Ic time | |
1935 | Controls automatic timing of commands. | |
1936 | If set, then any command which takes more than this many cpu seconds | |
1937 | will cause a line giving user, system, and real times and a utilization | |
1938 | percentage which is the ratio of user plus system times to real time | |
1939 | to be printed when it terminates. | |
1940 | .It Ic verbose | |
1941 | Set by the | |
1942 | .Fl v | |
1943 | command line option, causes the words of each command to be printed | |
1944 | after history substitution. | |
1945 | .El | |
1946 | .Ss Non-builtin command execution | |
1947 | When a command to be executed is found to not be a builtin command | |
1948 | the shell attempts to execute the command via | |
1949 | .Xr execve 2 . | |
1950 | Each word in the variable | |
1951 | .Ar path | |
1952 | names a directory from which the shell will attempt to execute the command. | |
1953 | If it is given neither a | |
1954 | .Fl c | |
1955 | nor a | |
1956 | .Fl t | |
1957 | option, the shell will hash the names in these directories into an internal | |
1958 | table so that it will only try an | |
1959 | .Ic exec | |
1960 | in a directory if there is a possibility that the command resides there. | |
1961 | This greatly speeds command location when a large number of directories | |
1962 | are present in the search path. | |
1963 | If this mechanism has been turned off (via | |
1964 | .Ic unhash ) , | |
1965 | or if the shell was given a | |
1966 | .Fl c | |
1967 | or | |
1968 | .Fl t | |
1969 | argument, and in any case for each directory component of | |
1970 | .Ar path | |
1971 | which does not begin with a `/', | |
1972 | the shell concatenates with the given command name to form a path name | |
1973 | of a file which it then attempts to execute. | |
1974 | .Pp | |
1975 | Parenthesized commands are always executed in a subshell. | |
1976 | Thus | |
1977 | .Pp | |
1978 | .Dl (cd ; pwd) ; pwd | |
1979 | .Pp | |
1980 | prints the | |
1981 | .Ar home | |
1982 | directory; leaving you where you were (printing this after the home directory), | |
1983 | while | |
1984 | .Pp | |
1985 | .Dl cd ; pwd | |
1986 | .Pp | |
1987 | leaves you in the | |
1988 | .Ar home | |
1989 | directory. | |
1990 | Parenthesized commands are most often used to prevent | |
1991 | .Ic chdir | |
1992 | from affecting the current shell. | |
1993 | .Pp | |
1994 | If the file has execute permissions but is not an | |
1995 | executable binary to the system, then it is assumed to be a | |
1996 | file containing shell commands and a new shell is spawned to read it. | |
1997 | .Pp | |
1998 | If there is an | |
1999 | .Ic alias | |
2000 | for | |
2001 | .Ic shell | |
2002 | then the words of the alias will be prepended to the argument list to form | |
2003 | the shell command. | |
2004 | The first word of the | |
2005 | .Ic alias | |
2006 | should be the full path name of the shell | |
2007 | (e.g. `$shell'). | |
2008 | Note that this is a special, late occurring, case of | |
2009 | .Ic alias | |
2010 | substitution, | |
2011 | and only allows words to be prepended to the argument list without modification. | |
2012 | .Ss Signal handling | |
2013 | The shell normally ignores | |
2014 | .Ar quit | |
2015 | signals. | |
2016 | Jobs running detached (either by | |
2017 | .Ic \&& | |
2018 | or the | |
2019 | .Ic bg | |
2020 | or | |
2021 | .Ic %... & | |
2022 | commands) are immune to signals generated from the keyboard, including | |
2023 | hangups. | |
2024 | Other signals have the values which the shell inherited from its parent. | |
2025 | The shell's handling of interrupts and terminate signals | |
2026 | in shell scripts can be controlled by | |
2027 | .Ic onintr . | |
2028 | Login shells catch the | |
2029 | .Ar terminate | |
2030 | signal; otherwise this signal is passed on to children from the state in the | |
2031 | shell's parent. | |
2032 | In no case are interrupts allowed when a login shell is reading the file | |
2033 | .Pa \&.logout . | |
2034 | .Sh AUTHOR | |
2035 | William Joy. | |
2036 | Job control and directory stack features first implemented by J.E. Kulp of | |
2037 | IIASA, Laxenburg, Austria, | |
2038 | with different syntax than that used now. | |
2039 | File name completion code written by Ken Greer, HP Labs. | |
2040 | Eight-bit implementation Christos S. Zoulas, Cornell University. | |
2041 | .Sh FILES | |
2042 | .Bl -tag -width /etc/passwd -compact | |
2043 | .It Pa ~/.cshrc | |
2044 | Read at beginning of execution by each shell. | |
2045 | .It Pa ~/.login | |
2046 | Read by login shell, after `.cshrc' at login. | |
2047 | .It Pa ~/.logout | |
2048 | Read by login shell, at logout. | |
2049 | .It Pa /bin/sh | |
2050 | Standard shell, for shell scripts not starting with a `#'. | |
2051 | .It Pa /tmp/sh* | |
2052 | Temporary file for `<<'. | |
2053 | .It Pa /etc/passwd | |
2054 | Source of home directories for `~name'. | |
2055 | .El | |
2056 | .Sh LIMITATIONS | |
2057 | Word lengths \- | |
2058 | Words can be no longer than 1024 characters. | |
2059 | The system limits argument lists to 10240 characters. | |
2060 | The number of arguments to a command which involves filename expansion | |
2061 | is limited to 1/6'th the number of characters allowed in an argument list. | |
2062 | Command substitutions may substitute no more characters than are | |
2063 | allowed in an argument list. | |
2064 | To detect looping, the shell restricts the number of | |
2065 | .Ic alias | |
2066 | substitutions on a single line to 20. | |
2067 | .Sh SEE ALSO | |
2068 | .Xr sh 1 , | |
2069 | .Xr access 2 , | |
2070 | .Xr execve 2 , | |
2071 | .Xr fork 2 , | |
2072 | .Xr killpg 2 , | |
2073 | .Xr pipe 2 , | |
2074 | .Xr sigvec 2 , | |
2075 | .Xr umask 2 , | |
2076 | .Xr setrlimit 2 , | |
2077 | .Xr wait 2 , | |
2078 | .Xr tty 4 , | |
2079 | .Xr a.out 5 , | |
2080 | .Xr environ 7 , | |
2081 | .br | |
2082 | .Em An introduction to the C shell | |
2083 | .Sh HISTORY | |
2084 | .Nm Csh | |
2085 | appeared in | |
2086 | .Bx 3 . | |
2087 | It | |
2088 | was a first implementation of a command language interpreter | |
2089 | incorporating a history mechanism (see | |
2090 | .Sx History Substitutions ) , | |
2091 | job control facilities (see | |
2092 | .Sx Jobs ) , | |
2093 | interactive file name | |
2094 | and user name completion (see | |
2095 | .Sx File Name Completion ) , | |
2096 | and a C-like syntax. | |
2097 | There are now many shells which also have these mechanisms, plus | |
2098 | a few more (and maybe some bugs too), which are available thru the | |
2099 | usenet, or with | |
2100 | .Bx | |
2101 | as contributed software like the | |
2102 | .Xr ksh korn\ shell . | |
2103 | .Sh BUGS | |
2104 | When a command is restarted from a stop, | |
2105 | the shell prints the directory it started in if this is different | |
2106 | from the current directory; this can be misleading (i.e. wrong) | |
2107 | as the job may have changed directories internally. | |
2108 | .Pp | |
2109 | Shell builtin functions are not stoppable/restartable. | |
2110 | Command sequences of the form `a ; b ; c' are also not handled gracefully | |
2111 | when stopping is attempted. If you suspend `b', the shell will then | |
2112 | immediately execute `c'. This is especially noticeable if this | |
2113 | expansion results from an | |
2114 | .Ar alias . | |
2115 | It suffices to place the sequence of commands in ()'s to force it to | |
2116 | a subshell, i.e. `( a ; b ; c )'. | |
2117 | .Pp | |
2118 | Control over tty output after processes are started is primitive; | |
2119 | perhaps this will inspire someone to work on a good virtual | |
2120 | terminal interface. In a virtual terminal interface much more | |
2121 | interesting things could be done with output control. | |
2122 | .Pp | |
2123 | Alias substitution is most often used to clumsily simulate shell procedures; | |
2124 | shell procedures should be provided rather than aliases. | |
2125 | .Pp | |
2126 | Commands within loops, prompted for by `?', are not placed in the | |
2127 | .Ic history | |
2128 | list. | |
2129 | Control structure should be parsed rather than being recognized as built-in | |
2130 | commands. This would allow control commands to be placed anywhere, | |
2131 | to be combined with `\&|', and to be used with `&' and `;' metasyntax. | |
2132 | .Pp | |
2133 | It should be possible to use the `:' modifiers on the output of command | |
2134 | substitutions. | |
2135 | All and more than one `:' modifier should be allowed on `$' substitutions. | |
2136 | .Pp | |
2137 | The way the | |
2138 | .Ic filec | |
2139 | facility is implemented is ugly and expensive. |