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