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