BSD 4_3 release
[unix-history] / usr / man / man1 / 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.\"
95f51977 5.\" @(#)csh.1 6.8 (Berkeley) 6/5/86
a838aafc 6.\"
95f51977 7.TH CSH 1 "June 5, 1986"
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
c635ed03 127indicating that the job which was started asynchronously was job number
a838aafc
KM
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
c635ed03 228and will sound the terminal bell to indicate that the expansion is
8633929c
EW
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.
c635ed03 342The words of an input line are numbered from 0,
a838aafc
KM
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.
c635ed03 527Within `"', a variable whose value consists of multiple words expands to a
a838aafc
KM
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
c635ed03 798above).
a838aafc
KM
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
32178f55
JL
927Shows the amount of dynamic memory acquired, broken down into used and
928free memory.
929With an argument shows the number of free and used blocks in each size
930category. The categories start at size 8 and double at each step.
931This command's output may vary across system types, since
932systems other than the VAX may use a different memory allocator.
a838aafc
KM
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
c635ed03 981Change the shell's working directory to directory
a838aafc
KM
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
c635ed03 1233are executed; otherwise if
a838aafc
KM
1234.IR expr2 ""
1235is true then the commands to the
c635ed03 1236second \fIelse\fR are executed, etc.
a838aafc
KM
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
00f19af8 1366.BR nice " +number"
a838aafc
KM
1367.br
1368.ns
1369.HP 5
1370.BR nice " command"
1371.br
1372.ns
1373.HP 5
00f19af8 1374.BR nice " +number command"
a838aafc
KM
1375.br
1376The first form sets the
32178f55 1377scheduling priority
a838aafc
KM
1378for this shell to 4.
1379The second form sets the
32178f55 1380priority
a838aafc
KM
1381to the given number.
1382The final two forms run command at priority 4 and
1383.I number
1384respectively.
32178f55
JL
1385The greater the number, the less cpu the process will get.
1386The super-user may specify negative priority by using `nice \-number ...'.
a838aafc 1387Command is always executed in a sub-shell, and the restrictions
0bddb73b 1388placed on commands in simple
a838aafc
KM
1389.I if
1390statements apply.
1391.HP 5
1392.B nohup
1393.br
1394.ns
1395.HP 5
1396.BR "nohup" " command"
1397.br
1398The first form can be used in shell scripts to cause hangups to be
1399ignored for the remainder of the script.
1400The second form causes the specified command to be run with hangups
1401ignored.
1402All processes detached with `&' are effectively
1403.I nohup'ed.
1404.HP 5
1405.B notify
1406.br
1407.ns
1408.HP 5
1409\fBnotify\ %\fRjob\ ...
1410.br
1411Causes the shell to notify the user asynchronously when the status of the
1412current or specified jobs changes; normally notification is presented
1413before a prompt. This is automatic if the shell variable
1414.I notify
1415is set.
1416.HP 5
1417.B onintr
1418.br
1419.ns
1420.HP 5
1421.BR onintr " \-"
1422.br
1423.ns
1424.HP 5
1425.BR onintr " label"
1426.br
1427Control the action of the shell on interrupts.
1428The first form restores the default action of the shell on interrupts
1429which is to terminate shell scripts or to return to the terminal command
1430input level.
1431The second form `onintr \-' causes all interrupts to be ignored.
1432The final form causes the shell to execute a `goto label' when
1433an interrupt is received or a child process terminates because
1434it was interrupted.
1435.IP
1436In any case, if the shell is running detached and interrupts are
1437being ignored, all forms of
1438.I onintr
1439have no meaning and interrupts
1440continue to be ignored by the shell and all invoked commands.
1441.HP 5
1442.BR "popd"
1443.br
1444.ns
1445.HP 5
1446.BR "popd" " +n"
1447.br
1448Pops the directory stack, returning to the new top directory.
c635ed03 1449With an argument `+\fIn\fR' discards the \fIn\fR\|th
a838aafc
KM
1450entry in the stack.
1451The elements of the directory stack are numbered from 0 starting at the top.
1452.HP 5
1453.BR "pushd"
1454.br
1455.ns
1456.HP 5
1457.BR "pushd" " name"
1458.br
1459.ns
1460.HP 5
1461.BR "pushd" " +n"
1462.br
1463With no arguments,
1464.I pushd
1465exchanges the top two elements of the directory stack.
1466Given a
1467.I name
1468argument,
1469.I pushd
1470changes to the new directory (ala
1471.I cd)
1472and pushes the old current working directory
1473(as in
1474.I csw)
1475onto the directory stack.
1476With a numeric argument, rotates the \fIn\fR\|th argument of the directory
1477stack around to be the top element and changes to it. The members
1478of the directory stack are numbered from the top starting at 0.
1479.HP 5
1480.BR rehash
1481.br
1482Causes the internal hash table of the contents of the directories in
1483the
1484.I path
1485variable to be recomputed. This is needed if new commands are added
1486to directories in the
1487.I path
1488while you are logged in. This should only be necessary if you add
1489commands to one of your own directories, or if a systems programmer
1490changes the contents of one of the system directories.
1491.HP 5
1492.BR repeat " count command"
1493.br
1494The specified
1495.I command
1496which is subject to the same restrictions
1497as the
1498.I command
1499in the one line
1500.I if
1501statement above,
1502is executed
1503.I count
1504times.
1505I/O redirections occur exactly once, even if
1506.I count
1507is 0.
1508.HP 5
1509.B set
1510.br
1511.ns
1512.HP 5
1513.BR set " name"
1514.br
1515.ns
1516.HP 5
1517.BR set " name=word"
1518.br
1519.ns
1520.HP 5
1521.BR set " name[index]=word"
1522.br
1523.ns
1524.HP 5
1525.BR set " name=(wordlist)"
1526.br
1527The first form of the command shows the value of all shell variables.
1528Variables which have other than a single word as value print as a parenthesized
1529word list.
1530The second form sets
1531.I name
1532to the null string.
1533The third form sets
1534.I name
1535to the single
1536.I word.
1537The fourth form sets
1538the
1539.I index'th
1540component of name to word;
1541this component must already exist.
1542The final form sets
1543.I name
1544to the list of words in
1545.I wordlist.
1546In all cases the value is command and filename expanded.
1547.IP
1548These arguments may be repeated to set multiple values in a single set command.
1549Note however, that variable expansion happens for all arguments before any
1550setting occurs.
1551.HP 5
4e72c72d
EW
1552.BR setenv
1553.br
1554.ns
1555.HP 5
a838aafc
KM
1556.BR setenv " name value"
1557.br
4e72c72d
EW
1558.ns
1559.HP 5
1560.BR setenv " name"
1561.br
1562The first form lists all current environment variables.
1563The last form sets the value of environment variable
a838aafc
KM
1564.I name
1565to be
1566.I value,
4e72c72d
EW
1567a single string. The second form sets
1568.I name
1569to an empty string.
a838aafc
KM
1570The most commonly used environment variable USER, TERM, and PATH
1571are automatically imported to and exported from the
1572.I csh
1573variables
1574.I user,
1575.I term,
1576and
1577.I path;
1578there is no need to use
1579.I setenv
1580for these.
1581.HP 5
1582.B shift
1583.br
1584.ns
1585.HP 5
1586.BR shift " variable"
1587.br
1588The members of
1589.I argv
1590are shifted to the left, discarding
1591.I argv[1].
1592It is an error for
1593.I argv
1594not to be set or to have less than one word as value.
1595The second form performs the same function on the specified variable.
1596.HP 5
1597.BR source " name"
1598.br
52547631
KM
1599.ns
1600.HP 5
1601.BR "source \-h" " name"
1602.br
a838aafc
KM
1603The shell reads commands from
1604.I name.
1605.I Source
1606commands may be nested; if they are nested too deeply the shell may
1607run out of file descriptors.
1608An error in a
1609.I source
1610at any level terminates all nested
1611.I source
1612commands.
52547631 1613Normally input during
a838aafc 1614.I source
52547631
KM
1615commands is not placed on the history list;
1616the \-h option causes the commands to be placed in the
1617history list without being executed.
a838aafc
KM
1618.HP 5
1619.B stop
1620.br
1621.ns
1622.HP 5
1623\fBstop\ %\fRjob\ ...
1624.br
1625Stops the current or specified job which is executing in the background.
1626.HP 5
1627.B suspend
1628.br
1629.ns
1630Causes the shell to stop in its tracks, much as if it had been sent a stop
1631signal with \fB^Z\fR. This is most often used to stop shells started by
1632.IR su (1).
1633.HP 5
1634.BR switch " (string)"
1635.br
1636.ns
1637.HP 5
1638.BR case " str1:"
1639.br
1640.ns
1641.HP 5
1642\ ...
1643.br
1644.ns
1645.HP 5
1646\
1647.B breaksw
1648.br
1649.ns
1650.HP 5
1651\&...
1652.br
1653.ns
1654.HP 5
1655.B default:
1656.br
1657.ns
1658.HP 5
1659\ ...
1660.br
1661.ns
1662.HP 5
1663\
1664.B breaksw
1665.br
1666.ns
1667.HP 5
1668.B endsw
1669.br
1670Each case label is successively matched, against the specified
1671.I string
1672which is first command and filename expanded.
1673The file metacharacters `*', `?' and `[...]' may be used in the case labels,
1674which are variable expanded.
1675If none of the labels match before a `default' label is found, then
1676the execution begins after the default label.
1677Each case label and the default label must appear at the beginning of a line.
1678The command
1679.I breaksw
1680causes execution to continue after the
1681.I endsw.
1682Otherwise control may fall through case labels and default labels as in C.
1683If no label matches and there is no default, execution continues after
1684the
1685.I endsw.
1686.HP 5
1687.B time
1688.br
1689.ns
1690.HP 5
1691.BR time " command"
1692.br
1693With no argument, a summary of time used by this shell and its children
1694is printed.
1695If arguments are given
1696the specified simple command is timed and a time summary
1697as described under the
1698.I time
52547631 1699variable is printed. If necessary, an extra shell is created to print the time
a838aafc
KM
1700statistic when the command completes.
1701.HP 5
1702.B umask
1703.br
1704.ns
1705.HP 5
1706.BR umask " value"
1707.br
1708The file creation mask is displayed (first form) or set to the specified
1709value (second form). The mask is given in octal. Common values for
1710the mask are 002 giving all access to the group and read and execute
1711access to others or 022 giving all access except no write access for
1712users in the group or others.
1713.HP 5
1714.BR unalias " pattern"
1715.br
1716All aliases whose names match the specified pattern are discarded.
1717Thus all aliases are removed by `unalias *'.
1718It is not an error for nothing to be
1719.I unaliased.
1720.HP 5
1721.BR unhash
1722.br
1723Use of the internal hash table to speed location of executed programs
1724is disabled.
1725.HP 5
e7f75797
KM
1726\fBunlimit\fR
1727.br
1728.ns
1729.HP 5
a838aafc
KM
1730\fBunlimit\fR \fIresource\fR
1731.br
1732.ns
1733.HP 5
e7f75797
KM
1734\fBunlimit\ \-h\fR
1735.br
1736.ns
1737.HP 5
1738\fBunlimit\ \-h\fR \fIresource\fR
a838aafc
KM
1739.br
1740Removes the limitation on \fIresource\fR. If no \fIresource\fR
e7f75797
KM
1741is specified, then all \fIresource\fR limitations are removed. If
1742\fB\-h\fR is given, the corresponding hard limits are removed. Only the
1743super-user may do this.
a838aafc
KM
1744.HP 5
1745.BR unset " pattern"
1746.br
1747All variables whose names match the specified pattern are removed.
1748Thus all variables are removed by `unset *'; this has noticeably
1749distasteful side-effects.
1750It is not an error for nothing to be
1751.I unset.
1752.HP 5
1753.BR unsetenv " pattern"
1754.br
1755Removes all variables whose name match the specified pattern from the
1756environment. See also the
1757.I setenv
1758command above and
1759.IR printenv (1).
1760.HP 5
1761.B wait
1762.br
1763All background jobs are waited for.
1764It the shell is interactive, then an interrupt can disrupt the wait,
1765at which time the shell prints names and job numbers of all jobs
1766known to be outstanding.
1767.HP 5
1768.BR while " (expr)"
1769.br
1770.ns
1771.HP 5
1772\ ...
1773.br
1774.ns
1775.HP 5
1776.B end
1777.br
1778While the specified expression evaluates non-zero, the commands between
1779the
1780.I while
1781and the matching end are evaluated.
1782.I Break
1783and
1784.I continue
1785may be used to terminate or continue the loop prematurely.
1786(The
1787.I while
1788and
1789.I end
1790must appear alone on their input lines.)
1791Prompting occurs here the first time through the loop as for the
1792.I foreach
1793statement if the input is a terminal.
1794.HP 5
1795\fB%\fRjob
1796.br
1797Brings the specified job into the foreground.
1798.HP 5
1799\fB%\fRjob \fB&\fR
1800.br
1801Continues the specified job in the background.
1802.HP 5
1803.B "@"
1804.br
1805.ns
1806.HP 5
1807.BR "@" " name = expr"
1808.br
1809.ns
1810.HP 5
1811.BR "@" " name[index] = expr"
1812.br
1813The first form prints the values of all the shell variables.
1814The second form sets the specified
1815.I name
1816to the value of
1817.I expr.
1818If the expression contains `<', `>', `&' or `|' then at least
1819this part of the expression must be placed within `(' `)'.
1820The third form assigns the value of
1821.I expr
1822to the
1823.I index'th
1824argument of
1825.I name.
1826Both
1827.I name
1828and its
1829.I index'th
1830component must already exist.
1831.IP
1832The operators `*=', `+=', etc are available as in C.
1833The space separating the name from the assignment operator is optional.
1834Spaces are, however, mandatory in separating components of
1835.I expr
1836which would otherwise be single words.
1837.IP
52547631 1838Special postfix `++' and `\-\|\-' operators increment and decrement
a838aafc
KM
1839.I name
1840respectively, i.e. `@ i++'.
1841.sh "Pre-defined and environment variables"
1842The following variables have special meaning to the shell.
1843Of these,
1844.I argv,
1845.I cwd,
1846.I home,
1847.I path,
1848.I prompt,
1849.I shell
1850and
1851.I status
1852are always set by the shell.
1853Except for
1854.I cwd
1855and
1856.I status
1857this setting occurs only at initialization;
1858these variables will not then be modified unless this is done
1859explicitly by the user.
1860.PP
1861This shell copies the environment variable USER into the variable
1862.I user,
1863TERM into
1864.I term,
1865and
1866HOME into
1867.I home,
1868and copies these back into the environment whenever the normal
1869shell variables are reset.
1870The environment variable PATH is likewise handled; it is not
1871necessary to worry about its setting other than in the file
1872.I \&.cshrc
1873as inferior
1874.I csh
1875processes will import the definition of
1876.I path
1877from the environment, and re-export it if you then change it.
a838aafc
KM
1878.TP 15
1879.B argv
1880\c
1881Set to the arguments to the shell, it is from this variable that
1882positional parameters are substituted, i.e. `$1' is replaced by
1883`$argv[1]', etc.
1884.TP 15
1885.B cdpath
1886\c
1887Gives a list of alternate directories searched to find subdirectories
1888in
1889.I chdir
1890commands.
1891.TP 15
1892.B cwd
1893The full pathname of the current directory.
1894.TP 15
1895.B echo
1896\c
1897Set when the
1898.B \-x
1899command line option is given.
1900Causes each command and its arguments
1901to be echoed just before it is executed.
1902For non-builtin commands all expansions occur before echoing.
1903Builtin commands are echoed before command and filename substitution,
1904since these substitutions are then done selectively.
1905.TP 15
8633929c
EW
1906.B filec
1907Enable file name completion.
1908\c
1909.TP 15
a838aafc
KM
1910.B histchars
1911\c
1912Can be given a string value to change the characters used in history
1913substitution. The first character of its value is used as the
1914history substitution character, replacing the default character !.
1915The second character of its value replaces the character \(ua in
1916quick substitutions.
1917.TP 15
1918.B history
1919\c
1920Can be given a numeric value to control the size of the history list.
1921Any command which has been referenced in this many events will not be
1922discarded.
1923Too large values of
1924.I history
1925may run the shell out of memory.
1926The last executed command is always saved on the history list.
1927.TP 15
1928.B home
1929\c
1930The home directory of the invoker, initialized from the environment.
1931The filename expansion of `\fB~\fR' refers to this variable.
1932.TP 15
1933.B ignoreeof
1934\c
1935If set the shell ignores
1936end-of-file from input devices which are terminals.
1937This prevents shells from accidentally being killed by control-D's.
1938.TP 15
1939.B mail
1940\c
1941The files where the shell checks for mail.
1942This is done after each command completion which will result in a prompt,
1943if a specified interval has elapsed.
1944The shell says `You have new mail.'
1945if the file exists with an access time not greater than its modify time.
1946.IP
1947If the first word of the value of
1948.I mail
1949is numeric it specifies a different mail checking interval, in seconds,
1950than the default, which is 10 minutes.
1951.IP
1952If multiple mail files are specified, then the shell says
1953`New mail in
1954.IR name '
1955when there is mail in the file
1956.I name.
1957.TP 15
1958.B noclobber
1959\c
1960As described in the section on
1961.I Input/output,
1962restrictions are placed on output redirection to insure that
1963files are not accidentally destroyed, and that `>>' redirections
1964refer to existing files.
1965.TP 15
1966.B noglob
1967\c
1968If set, filename expansion is inhibited.
1969This is most useful in shell scripts which are not dealing with filenames,
1970or after a list of filenames has been obtained and further expansions
1971are not desirable.
1972.TP 15
1973.B nonomatch
1974\c
1975If set, it is not an error for a filename expansion to not match any
1976existing files; rather the primitive pattern is returned.
1977It is still an error for the primitive pattern to be malformed, i.e.
1978`echo [' still gives an error.
1979.TP 15
1980.B notify
1981\c
1982If set, the shell notifies asynchronously of job completions. The
1983default is to rather present job completions just before printing
1984a prompt.
1985.TP 15
1986.B path
1987\c
1988Each word of the path variable specifies a directory in which
1989commands are to be sought for execution.
1990A null word specifies the current directory.
1991If there is no
1992.I path
1993variable then only full path names will execute.
1994The usual search path is `.', `/bin' and `/usr/bin', but this
1995may vary from system to system.
1996For the super-user the default search path is `/etc', `/bin' and `/usr/bin'.
1997A shell which is given neither the
1998.B \-c
1999nor the
2000.B \-t
2001option will normally hash the contents of the directories in the
2002.I path
2003variable after reading
2004.I \&.cshrc,
2005and each time the
2006.I path
2007variable is reset. If new commands are added to these directories
2008while the shell is active, it may be necessary to give the
2009.I rehash
2010or the commands may not be found.
2011.TP 15
2012.B prompt
2013\c
2014The string which is printed before each command is read from
2015an interactive terminal input.
2016If a `!' appears in the string it will be replaced by the current event number
2017unless a preceding `\e' is given.
2018Default is `% ', or `# ' for the super-user.
2019.TP 15
52547631
KM
2020.B savehist
2021\c
2022is given a numeric value to control the number of entries of the
2023history list that are saved in ~/.history when the user logs out.
2024Any command which has been referenced in this many events will be saved.
2025During start up the shell sources ~/.history into the history list
2026enabling history to be saved across logins.
2027Too large values of
2028.I savehist
2029will slow down the shell during start up.
2030.TP 15
a838aafc
KM
2031.B shell
2032\c
2033The file in which the shell resides.
2034This is used in forking shells to interpret files which have execute
2035bits set, but which are not executable by the system.
2036(See the description of
2037.I "Non-builtin Command Execution"
2038below.)
2039Initialized to the (system-dependent) home of the shell.
2040.TP 15
2041.B status
2042\c
2043The status returned by the last command.
2044If it terminated abnormally, then 0200 is added to the status.
2045Builtin commands which fail return exit status `1',
2046all other builtin commands set status `0'.
2047.TP 15
2048.B time
2049\c
2050Controls automatic timing of commands.
2051If set, then any command which takes more than this many cpu seconds
2052will cause a line giving user, system, and real times and a utilization
2053percentage which is the ratio of user plus system times to real time
2054to be printed when it terminates.
2055.TP 15
2056.B verbose
2057\c
2058Set by the
2059.B \-v
2060command line option, causes the words of each command to be printed
2061after history substitution.
2062.sh "Non-builtin command execution"
2063When a command to be executed is found to not be a builtin command
2064the shell attempts to execute the command via
52547631 2065.IR execve (2).
a838aafc
KM
2066Each word in the variable
2067.I path
2068names a directory from which the shell will attempt to execute the command.
2069If it is given neither a
2070.B \-c
2071nor a
2072.B \-t
2073option, the shell will hash the names in these directories into an internal
2074table so that it will only try an
2075.I exec
2076in a directory if there is a possibility that the command resides there.
2077This greatly speeds command location when a large number of directories
2078are present in the search path.
2079If this mechanism has been turned off (via
52547631 2080.IR unhash ),
a838aafc
KM
2081or if the shell was given a
2082.B \-c
2083or
2084.B \-t
2085argument, and in any case for each directory component of
2086.I path
2087which does not begin with a `/',
2088the shell concatenates with the given command name to form a path name
2089of a file which it then attempts to execute.
2090.PP
2091Parenthesized commands are always executed in a subshell.
2092Thus `(cd ; pwd) ; pwd' prints the
2093.I home
2094directory; leaving you where you were (printing this after the home directory),
2095while `cd ; pwd' leaves you in the
2096.I home
2097directory.
2098Parenthesized commands are most often used to prevent
2099.I chdir
2100from affecting the current shell.
2101.PP
2102If the file has execute permissions but is not an
2103executable binary to the system, then it is assumed to be a
52547631 2104file containing shell commands and a new shell is spawned to read it.
a838aafc
KM
2105.PP
2106If there is an
2107.I alias
2108for
2109.I shell
2110then the words of the alias will be prepended to the argument list to form
2111the shell command.
2112The first word of the
2113.I alias
2114should be the full path name of the shell
2115(e.g. `$shell').
2116Note that this is a special, late occurring, case of
2117.I alias
2118substitution,
2119and only allows words to be prepended to the argument list without modification.
2120.sh "Argument list processing"
2121If argument 0 to the shell is `\-' then this
2122is a login shell.
2123The flag arguments are interpreted as follows:
2124.TP 5
0bddb73b
MK
2125.B \-b
2126\c
2127This flag forces a ``break'' from option processing, causing any further
2128shell arguments to be treated as non-option arguments.
2129The remaining arguments will not be interpreted as shell options.
2130This may be used to pass options to a shell script without confusion
2131or possible subterfuge.
2132The shell will not run a set-user ID script without this option.
2133.TP 5
a838aafc
KM
2134.B \-c
2135\c
2136Commands are read from the (single) following argument which must
2137be present.
2138Any remaining arguments are placed in
2139.I argv.
2140.TP 5
2141.B \-e
2142\c
2143The shell exits if any invoked command terminates abnormally
2144or yields a non-zero exit status.
2145.TP 5
2146.B \-f
2147\c
2148The shell will start faster, because it will neither search for nor
2149execute commands from the file
c635ed03 2150`\&.cshrc' in the invoker's home directory.
a838aafc
KM
2151.TP 5
2152.B \-i
2153\c
2154The shell is interactive and prompts for its top-level input,
2155even if it appears to not be a terminal.
2156Shells are interactive without this option if their inputs
2157and outputs are terminals.
2158.TP 5
2159.B \-n
2160\c
2161Commands are parsed, but not executed.
52547631 2162This aids in syntactic checking of shell scripts.
a838aafc
KM
2163.TP 5
2164.B \-s
2165\c
2166Command input is taken from the standard input.
2167.TP 5
2168.B \-t
2169\c
2170A single line of input is read and executed.
2171A `\e' may be used to escape the newline at the end of this
2172line and continue onto another line.
2173.TP 5
2174.B \-v
2175\c
2176Causes the
2177.I verbose
2178variable to be set, with the effect
2179that command input is echoed after history substitution.
2180.TP 5
2181.B \-x
2182\c
2183Causes the
2184.I echo
2185variable to be set, so that commands are echoed immediately before execution.
2186.TP 5
2187.B \-V
2188\c
2189Causes the
2190.I verbose
2191variable to be set even before `\&.cshrc' is executed.
2192.TP 5
2193.B \-X
2194\c
2195Is to
2196.B \-x
2197as
2198.B \-V
2199is to
2200.B \-v.
2201.PP
c635ed03 2202After processing of flag arguments, if arguments remain but none of the
a838aafc
KM
2203.B \-c,
2204.B \-i,
2205.B \-s,
2206or
2207.B \-t
c635ed03 2208options was given, the first argument is taken as the name of a file of
a838aafc
KM
2209commands to be executed.
2210The shell opens this file, and saves its name for possible resubstitution
2211by `$0'.
2212Since many systems use either the standard version 6 or version 7 shells
2213whose shell scripts are not compatible with this shell, the shell will
2214execute such a `standard' shell if the first character of a script
2215is not a `#', i.e. if the script does not start with a comment.
2216Remaining arguments initialize the variable
2217.I argv.
2218.sh "Signal handling"
2219The shell normally ignores
2220.I quit
2221signals.
2222Jobs running detached (either by `&' or the \fIbg\fR or \fB%... &\fR
2223commands) are immune to signals generated from the keyboard, including
2224hangups.
2225Other signals have the values which the shell inherited from its parent.
2226The shells handling of interrupts and terminate signals
2227in shell scripts can be controlled by
2228.I onintr.
2229Login shells catch the
2230.I terminate
2231signal; otherwise this signal is passed on to children from the state in the
2232shell's parent.
2233In no case are interrupts allowed when a login shell is reading the file
2234`\&.logout'.
2235.SH AUTHOR
2236William Joy.
2237Job control and directory stack features first implemented by J.E. Kulp of
2238I.I.A.S.A, Laxenburg, Austria,
8633929c
EW
2239with different syntax than that used now. File name completion
2240code written by Ken Greer, HP Labs.
a838aafc
KM
2241.SH FILES
2242.ta 1.75i
2243.nf
2244~/.cshrc Read at beginning of execution by each shell.
2245~/.login Read by login shell, after `.cshrc' at login.
2246~/.logout Read by login shell, at logout.
2247/bin/sh Standard shell, for shell scripts not starting with a `#'.
2248/tmp/sh* Temporary file for `<<'.
2249/etc/passwd Source of home directories for `~name'.
2250.fi
2251.SH LIMITATIONS
2252Words can be no longer than 1024 characters.
2253The system limits argument lists to 10240 characters.
2254The number of arguments to a command which involves filename expansion
2255is limited to 1/6'th the number of characters allowed in an argument list.
2256Command substitutions may substitute no more characters than are
2257allowed in an argument list.
2258To detect looping, the shell restricts the number of
2259.I alias
52547631 2260substitutions on a single line to 20.
a838aafc 2261.SH "SEE ALSO"
52547631
KM
2262sh(1), access(2), execve(2), fork(2), killpg(2), pipe(2), sigvec(2),
2263umask(2), setrlimit(2), wait(2), tty(4), a.out(5), environ(7),
a838aafc
KM
2264`An introduction to the C shell'
2265.SH BUGS
2266When a command is restarted from a stop,
2267the shell prints the directory it started in if this is different
2268from the current directory; this can be misleading (i.e. wrong)
2269as the job may have changed directories internally.
2270.PP
2271Shell builtin functions are not stoppable/restartable.
2272Command sequences of the form `a ; b ; c' are also not handled gracefully
2273when stopping is attempted. If you suspend `b', the shell will then
2274immediately execute `c'. This is especially noticeable if this
2275expansion results from an
2276.I alias.
2277It suffices to place the sequence of commands in ()'s to force it to
2278a subshell, i.e. `( a ; b ; c )'.
2279.PP
2280Control over tty output after processes are started is primitive;
2281perhaps this will inspire someone to work on a good virtual
2282terminal interface. In a virtual terminal interface much more
2283interesting things could be done with output control.
2284.PP
2285Alias substitution is most often used to clumsily simulate shell procedures;
2286shell procedures should be provided rather than aliases.
2287.PP
2288Commands within loops, prompted for by `?', are not placed in the
2289.I history
2290list.
2291Control structure should be parsed rather than being recognized as built-in
2292commands. This would allow control commands to be placed anywhere,
2293to be combined with `|', and to be used with `&' and `;' metasyntax.
2294.PP
2295It should be possible to use the `:' modifiers on the output of command
2296substitutions.
2297All and more than one `:' modifier should be allowed on `$' substitutions.
32178f55
JL
2298.PP
2299The way the
2300.B filec
2301facility is implemented is ugly and expensive.