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