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