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