% -*-LaTeX-*-
% Converted automatically from troff to LaTeX by tr2tex on Thu Feb 19 12:47:28 1987
% tr2tex was written by Kamal Al-Yahya at Stanford University
% (Kamal%Hanauma@SU-SCORE.ARPA)


\documentstyle[troffman]{article}
\begin{document}
%
% input file: tt
%
\def\sh#1{\nwl
%.ne 5
\par
%
\bf #1%
\rm \par
}
%.if n .ds ua \o'^|'
%.if t .ds ua \(ua
%.if n .ds aa '
%.if t .ds aa \(aa
%.if n .ds ga `
%.if t .ds ga \(ga
%.if t .tr *\(**
\phead{CSH}{1}{18\ July\ 1983}

\shead{NAME}
csh -- a shell (command interpreter) with C-like syntax
\shead{SYNOPSIS}
{\bf csh}
[
{\bf --cef\/instvVxX}
] [
arg ...
]
\shead{DESCRIPTION}
{\it Csh}
is a first implementation of a command language interpreter
incorporating a history mechanism (see
{\bf History\ Substitutions)}%
\rm ,
job control facilities (see
{\bf Jobs)%
\rm ,}
and a C-like syntax.
To be able to use its job control facilities, users of
{\it csh}
must (and automatically) use the new tty driver fully described in
{\it tty}{\rm (4).}
This new tty driver allows generation of interrupt characters
from the keyboard to tell jobs to stop.  See
{\it stty}{\rm (1)}
for details on setting options in the new tty driver.
\par
An instance of
{\it csh}
begins by executing commands from the file %
\it .cshrc \rm%
 in the
{\it home}
directory of the invoker.
If this is a login shell, then it also executes commands from the file
{\it .login}
there.
It is typical for users on crt's to put the command %
\bf stty crt \rm%
 in their
{\it .login}
file, and to also invoke
{\it tset}{\rm (1)}
there.
\par
In the normal case, the shell will then begin reading commands from the
terminal, prompting with %
\bf \% \rm%
 .
Processing of arguments and the use of the shell to process files
containing command scripts will be described later.
\par
The shell then repeatedly performs the following actions:
a line of command input is read and broken into
{\it words}{\rm .}
This sequence of words is placed on the command history list and then parsed.
Finally each command in the current line is executed.
\par
When a login shell terminates, it executes commands from the file %
\it .logout \rm%

in the users home directory.
\sh{Lexical\ structure}
The shell splits input lines into words at blanks and tabs with the
following exceptions.
The characters
%
\bf \&%
\rm , %
\bf $|$%
\rm , %
\bf ;%
\rm , %
\bf $<$%
\rm , %
\bf $>$%
\rm , %
\bf (%
\rm , and %
\bf ) %
\rm 
form separate words.
If doubled in 
%
\bf \&\&%
\rm , %
\bf $|$\,\,$|$%
\rm , %
\bf $<$$<$%
\rm ,
or
{\bf $>$$>$,}
these pairs form single words.
These parser metacharacters may be made part of other words. To prevent their
special meaning, precede them with %
\bf \bs %
\rm .
A newline preceded by a %
\bf \bs  %
\rm  is equivalent to a blank.
\par
In addition, strings enclosed in matched pairs of quotations
%
\bf %
\rm , %
\bf %
\rm , or %
\bf "%
\rm ,
form parts of a word; metacharacters in these strings, including blanks
and tabs, do not form separate words.
These quotations have semantics to be described subsequently.
Within pairs of %
\bf ' %
\rm  or %
\bf " %
\rm  characters, a newline 
preceded by a %
\bf \bs  %
\rm  gives a true newline character.
\par
When the shell's input is not a terminal,
the character %
\bf \# %
\rm  introduces a comment which continues to the 
end of the input line.
This special meaning is prevented when the %
\bf \# %
\rm  is preceded 
by %
\bf \bs  %
\rm  and is in quotations using %
\bf `%
\rm , %
\bf '%
\rm , 
and %
\bf "%
\rm .
\sh{Commands}
A simple command is a sequence of words, the first of which
specifies the command to be executed.
A simple command or
a sequence of simple commands separated by %
\bf $|$ %
\rm  characters
forms a pipeline.
The output of each command in a pipeline is connected to the input of the next.
Sequences of pipelines may be separated by %
\bf ;%
\rm , and are then executed
sequentially.
A sequence of pipelines may be executed without immediately 
waiting for it to terminate by following it with an %
\bf \&%
\rm .
\par
Any of the above may be placed in %
\bf (' `) %
\rm  to form a 
simple command that may be a component of a pipeline, etc.
It is also possible to separate pipelines with %
\bf $|$\,\,$|$ %
\rm  or 
%
\bf \&\& %
\rm  indicating, as in the C language,
that the second is to be executed only if the first fails or succeeds
respectively. (See
{\bf Expressions.)}
\sh{Jobs}
The shell associates a %
\it job %
\rm  with each pipeline.  It keeps
a table of current jobs, printed by the
%
\it jobs %
\rm  command, and assigns them small integer numbers.  When
a job is started asynchronously with %
\bf \&%
\rm , the shell prints a 
line which looks like:
\par
%.DT
	[1] 1234
\par
indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process ID was 1234.
\par
If you are running a job and wish to do something else, you may hit the keys
%
\bf \^{}Z %
\rm  (control-Z). This sends a STOP signal to the current job.
The shell will normally indicate that the job has been `Stopped',
and print another prompt.  You can then manipulate the state of this job,
putting it in the background with the %
\it bg %
\rm  command, or run some other
commands and eventually bring the job back into the foreground with
the foreground command %
\it fg%
\rm .  A %
\bf \^{}Z %
\rm  takes effect immediately, and
is like an interrupt in that pending output and unread input are discarded
when it is typed.  There is another special command, %
\bf \^{}Y%
\rm , which does 
not generate a STOP signal until a program attempts to
{\it read}{\rm (2)}
it.
This can usefully be typed ahead when you have prepared some commands
for a job which you wish to stop after it has read them.
\par
A job being run in the background will stop if it tries to read
from the terminal.  Background jobs are normally allowed to produce output,
but this can be disabled by giving the command ``stty tostop''.
If you set this
tty option, background jobs will stop when they try to produce
output, just as they do when they try to read input.
\par
There are several ways to refer to jobs in the shell.  The character
%
\bf \% %
\rm  introduces a job name.  If you wish to refer to job number 1, you can
name it as %
\bf \%1%
\rm .  Just naming a job brings it to the foreground; thus
%
\bf \%1 %
\rm  is a synonym for %
\bf fg \%1%
\rm , bringing job 1 back into the foreground.
Similarly, entering %
\bf \%1 \& %
\rm  resumes job 1 in the background.
Jobs can also be named by prefixes of the string typed in to start them,
if these prefixes are unambiguous, thus %
\bf \%ex %
\rm  would normally restart
a suspended
{\it ex}{\rm (1)}
job, if there were only one suspended job whose name began with
the string %
\bf ex%
\rm .  It is also possible to say %
\bf \%?string%
\rm .
This specifies a job whose text contains
{\it string,}
if there is only one such job.
\par
The shell maintains a notion of the current and previous jobs.
In output pertaining to jobs, the current job is marked with a %
\bf + %
\rm 
and the previous job with a %
\bf --%
\rm .  The abbreviation %
\bf \%+ %
\rm  refers
to the current job and %
\bf \%-- %
\rm  refers to the previous job.  For close
analogy with the syntax of the
{\it history}
mechanism (described below),
%
\bf \%\% %
\rm  is also a synonym for the current job.
\sh{Status\ reporting}
This shell learns immediately whenever a process changes state.
It normally informs you whenever a job becomes blocked so that
no further progress is possible, but only just before it prints
a prompt.  This is done so that it does not otherwise disturb your work.
If, however, you set the shell variable
{\it notify,}
the shell will notify you immediately of changes of status in background
jobs.
There is also a shell command
{\it notify}
which marks a single process so that its status changes will be immediately
reported.  By default,
{\it notify}
marks the current process;
simply say %
\bf notify %
\rm  after starting a background job to mark it.
\par
If you try to leave the shell while jobs are stopped, you will
be warned that `You have stopped jobs.'  You may use the %
\it jobs %
\rm 
command to see what they are.  If you do this and/or immediately try to
exit again, the shell will not warn you a second time, and the suspended
jobs will be terminated.
\sh{Substitutions}
We now describe the various transformations the shell performs on the
input in the order in which they occur.
\sh{History\ substitutions}
History substitutions place words from previous command input as portions
of new commands, making it easy to repeat commands, repeat arguments
of a previous command in the current command, or fix spelling mistakes
in the previous command with little typing and a high degree of confidence.
History substitutions begin with the character %
\bf ! %
\rm  and may begin
{\it anywhere}
in the input stream (with the proviso that they
{\it do\ not}
nest.)
This %
\bf ! %
\rm  may be preceded by an 
%
\bf \bs  %
\rm  to prevent its special meaning; for
convenience, a %
\bf ! %
\rm  is passed unchanged when it is followed
by a blank, tab, newline, %
\bf =%
\rm , or %
\bf (%
\rm .
(History substitutions also occur when an input line begins with %
\bf %
\rm .
This special abbreviation will be described later.)
Any input line which contains history substitution is echoed on the terminal
before it is executed as it could have been typed without history substitution.
\par
Commands that are input from the terminal and which consist of one or 
more words are saved on the history list.
The history substitutions reintroduce sequences of words from these
saved commands into the input stream.
Commands are numbered sequentially from 1.
The size of the history list is controlled by the
{\it history}
variable.  The previous command is always retained, regardless of its value.
\par
For definiteness, consider the following output from the
{\it history}
command:
\par
%.DT
\nwl
	\ 9  write michael
\nwl
	10  ex write.c
\nwl
	11  cat oldwrite.c
\nwl
	12  diff *write.c
\par
The commands are shown with their event numbers.
It is not usually necessary to use event numbers, but the current event
number can be made part of the
{\it prompt}
by placing %
\bf ! %
\rm  in the prompt string.
\par
With the current event (13) we can refer to previous events by event
number %
\bf !11%
\rm , relatively (as in %
\bf !--2%
\rm , referring to the same event),
by a prefix of a command word
(as in %
\bf !d %
\rm  for event 12, or %
\bf !wri %
\rm  for event 9), or by a string contained in
a word in the command (as in %
\bf !?mic?%
\rm , also referring to event 9).
These forms, without further modification, simply reintroduce the words
of the specified events, each separated by a single blank.
As a special case, %
\bf !! %
\rm  refers to the previous command; thus 
%
\bf !! %
\rm 
alone is essentially a
{\it redo.}
\par
To select words from an event, we can follow the event specification by
%
\bf : %
\rm  and a designator for the desired words.
The words of an input line are numbered from 0,
the first (usually command) word being 0, the second word (first argument)
being 1, etc.
The basic word designators are:
\par
%.DT
\nofill
	0	first (command) word
	%
\it n %
\rm 	%
\it n%
\rm \,'th argument
		first argument,  i.e. `1'
	\$	last argument
	\%	word matched by (immediately preceding) ?%
\it s%
\rm \,? search
	%
\it x%
\rm \,--%
\it y %
\rm 	range of words
	--%
\it y %
\rm 	abbreviates `0--%
\it y%
\rm \,'
	*	abbreviates `--\$', or nothing if only 1 word in event
	%
\it x%
\rm \,*	abbreviates `%
\it x%
\rm \,--\$'
	%
\it x%
\rm \,--	like `%
\it x%
\rm \,*' but omitting word `\$'
\fill
\par
The %
\bf : %
\rm  separating the event specification from the word designator
can be omitted if the argument selector begins with %
\bf %
\rm ,
%
\bf \$%
\rm , %
\bf *%
\rm ,
%
\bf --%
\rm , or %
\bf \%%
\rm .
A sequence of modifiers, each preceded by %
\bf :%
\rm , can be placed
after the optional word designator.
The following modifiers are defined:
%.ta .5i 1.2i
\par
\nofill
	%
\bf h %
\rm 	Remove a trailing pathname component, leaving the head.
	%
\bf r %
\rm 	Remove a trailing `.xxx' component, leaving the root name.
	%
\bf e %
\rm 	Remove all but the extension `.xxx' part.
	%
\bf s %
\rm  /%
\it l%
\rm \,/%
\it r%
\rm \,/	Substitute %
\it r %
\rm  for %
\it l %
\rm 
	%
\bf t %
\rm 	Remove all leading pathname components, leaving the tail.
	%
\bf \& %
\rm 	Repeat the previous substitution.
	%
\bf g %
\rm 	Apply the change globally, prefixing the above, e.g. %
\bf g\&%
\rm .
	%
\bf p %
\rm 	Print the new command, but do not execute it.
	%
\bf q %
\rm 	Quote the substituted words, preventing further substitutions.
	%
\bf x %
\rm 	Like %
\bf q%
\rm , but break into words at blanks, tabs, and newlines.
\fill
\par
Unless preceded by a %
\bf g%
\rm , the modification is applied only to the first
modifiable word.  With substitutions, it is an error for no word to be
applicable.
\par
The left-hand side of substitutions are not regular expressions in the sense
of the editors, but rather strings.
Any character may be used as the delimiter in place of %
\bf /%
\rm ;
a %
\bf \bs  %
\rm  quotes the delimiter into the
{\it l}{\rm }
and
{\it r}{\rm }
strings.
The character %
\bf \& %
\rm  in the right-hand side is replaced by the text from
the left.
A %
\bf \bs  %
\rm  quotes %
\bf \& %
\rm  also.
A null
{\it l}{\rm }
uses the previous string either from a
{\it l}{\rm }
or from a
contextual scan string
{\it s}{\rm }
in %
\bf !?%
\it s%
\rm \,?%
\rm .
The trailing delimiter in the substitution may be omitted if a newline
follows immediately, as may the trailing %
\bf ? %
\rm  in a contextual scan.
\par
A history reference may be given without an event 
specification, e.g. %
\bf !\$%
\rm .
In this case, the reference is to the previous command.  However, if a previous
history reference occurred on the same line, this form repeats
the previous reference.
Thus %
\bf !?foo? !\$ %
\rm  gives the first and last arguments
from the command matching %
\bf ?foo?%
\rm .
\par
A special abbreviation of a history reference occurs when the first
nonblank character of an input line is a %
\bf %
\rm .
This is equivalent to %
\bf !:s %
\rm  providing a convenient shorthand 
for substitutions on the text of the previous line.
Thus, %
\bf lblib %
\rm  fixes the spelling of 
%
\bf lib %
\rm 
in the previous command.
Finally, a history substitution may be surrounded with %
\bf \{ %
\rm  and 
%
\bf \}%
\rm ,
if necessary, to insulate it from the characters which follow.
Thus, after %
\bf ls --ld \~{}paul%
\rm , we might do 
%
\bf !\{l\}a %
\rm  to do %
\bf ls --ld \~{}paula%
\rm ,
while %
\bf !la %
\rm  would look for a command starting %
\bf la%
\rm .
\par
%.if n .ul
%
\bf Quotations\ with\ '\ and\ " %
\rm 
\par
The quotation of strings by %
\bf ' %
\rm  and %
\bf " %
\rm  can be used
to prevent all or some of the remaining substitutions.
Strings enclosed in %
\bf ' %
\rm  are prevented any further interpretation.
Strings enclosed in %
\bf " %
\rm  may be expanded as described below.
\par
In both cases, the resulting text becomes all or part of a single word;
only in one special case (see
{\bf Command\ Substitition}
below) does a %
\bf " %
\rm  quoted string yield parts of more than one word;
%
\bf ' %
\rm  quoted strings never do.
\sh{Alias\ substitution}
The shell maintains a list of aliases which can be established, displayed,
and modified by the
{\it alias}
and
{\it unalias}
commands.
After a command line is scanned, it is parsed into distinct commands and
the first word of each command, left-to-right, is checked to see if it
is an alias.
If it is, the alias text is reread
with the history mechanism available
as though that command were the previous input line.
The resulting words replace the
command and argument list.
If no reference is made to the history list, then the argument list is
left unchanged.
\par
Thus, if the alias for %
\bf ls --l %
\rm  is %
\bf ls%
\rm , the command
%
\bf ls /usr %
\rm  would map to
%
\bf ls --l /usr%
\rm , the argument list here being undisturbed.
Similarly, if %
\bf lookup %
\rm  was an alias for 
%
\bf grep ! /etc/passwd%
\rm , then
%
\bf lookup bill %
\rm  would map to %
\bf grep bill /etc/passwd%
\rm .
\par
If an alias is found, the word transformation of the input text
is performed and the process begins again on the reformed input line.
Looping is prevented, if the first word of the new text is the same as the old,
by flagging it to prevent further aliasing.
Other loops are detected and cause an error.
\par
Note that the mechanism allows aliases to introduce parser metasyntax.
Thus, we can %
\bf alias print \bs !* \,$|$\, lpr %
\rm  to make a command which
{\it pr's}
its arguments to the line printer.
\sh{Variable\ substitution}
The shell maintains a set of variables, each of which has as value a list
of zero or more words.
Some of these variables are set by the shell or referred to by it.
For instance, the
{\it argv}
variable is an image of the shell's argument list, and words of this
variable's value are referred to in special ways.
\par
The values of variables may be displayed and changed by using the
{\it set}
and
{\it unset}
commands.
Of the variables referred to by the shell, a number are toggles;
the shell does not care what their value is,
only whether they are set or not.
For instance, the
{\it verbose}
variable is a toggle which causes command input to be echoed.
The setting of this variable results from the
{\bf --v}
command line option.
\par
Other operations treat variables numerically.
The %
\bf @ %
\rm  command permits numeric calculations to be 
performed and the result assigned to a variable.
Variable values are, however, always represented as zero or more strings.
For the purpose of numeric operations, the null string is considered to be
zero, and the second and subsequent words of multiword values are ignored.
\par
After the input line is aliased and parsed, and before each command
is executed, variable substitution
is performed keyed by %
\bf \$ %
\rm  characters.
This expansion can be prevented by preceding the %
\bf \$ %
\rm  with 
a %
\bf \bs  %
\rm  except within %
\bf "%
\rm 's where it
{\it always}
occurs, and within %
\bf '%
\rm 's where it
{\it never}
occurs.
Strings quoted by %
\bf  %
\rm  are interpreted later (see
{\bf Command\ substitution}
below) so %
\bf \$ %
\rm  substitution does not occur there until
later, if at all.
A %
\bf \$ %
\rm  is passed unchanged if followed by a blank, tab, or end-of-line.
\par
Input/output redirections are recognized before variable expansion,
and are variable expanded separately.
Otherwise, the command name and entire argument list are expanded together.
It is thus possible for the first command word to this point to generate
more than one word, the first of which becomes the command name,
and the rest of which become arguments.
\par
Unless enclosed in %
\bf " %
\rm  or given the %
\bf :q %
\rm  modifier,
the results of variable
substitution may eventually be command and filename substituted.
Within %
\bf " %
\rm  a variable whose value consists of multiple words expands
to a portion of a single word, with the words of the variables value
separated by blanks.
When the %
\bf :q %
\rm  modifier is applied to a substitution,
the variable expands to multiple words with each word separated
by a blank and quoted to prevent later command or filename substitution.
\par
The following metasequences are provided for introducing variable values into
the shell input.
Except as noted, it is an error to reference a variable which is not set.
\begin{TPlist}{\$name}
\item[{\$name}]
\nwl
\item[{\$\{name\}}]
\nwl
Are replaced by the words of the value of variable
{\it name,}
each separated by a blank.
Braces insulate
{\it name}
from following characters which would otherwise be part of it.
Shell variables have names consisting of up to 20 letters, and digits
starting with a letter.  The underscore character is considered a letter.
\nwl
If
{\it name}
is not a shell variable, but is set in the environment, then
that value is returned (but %
\bf : %
\rm  modifiers and the other forms
given below are not available in this case).
\item[{\$name[selector]}]
\nwl
\item[{\$\{name[selector]\}}]
\nwl
May be used to select only some of the words from the value of
{\it name.}
The selector is subjected to %
\bf \$ %
\rm  substitution and may
consist of a single number or two numbers separated by a %
\bf --%
\rm .
The first word of a variables value is numbered %
\bf 1%
\rm .
If the first number of a range is omitted, it defaults to %
\bf 1%
\rm .
If the last member of a range is omitted, it defaults to %
\bf \$\#name%
\rm .
The selector %
\bf * %
\rm  selects all words.
It is not an error for a range to be empty if the second argument is omitted
or in range.
\item[{\$\#name}]
\nwl
\item[{\$\{\#name\}}]
\nwl
Gives the number of words in the variable.
This is useful for later use in a %
\bf [%
\rm selector%
\bf ]%
\rm .
\item[{\$0}]
\nwl
Substitutes the name of the file from which command input is being read.
An error occurs if the name is not known.
\item[{\$number}]
\nwl
\item[{\$\{number\}}]
\nwl
Equivalent to %
\bf \$argv[%
\rm number%
\bf ]%
\rm .
\item[{\$*}]
\nwl
Equivalent to %
\bf \$argv[*]%
\rm .
\end{TPlist}
The modifiers %
\bf :h%
\rm , %
\bf :t%
\rm , %
\bf :r%
\rm , %
\bf :q%
\rm , and %
\bf :x %
\rm  may be applied to
the substitutions above, as may %
\bf :gh%
\rm , %
\bf :gt%
\rm , and %
\bf :gr%
\rm .
If braces %
\bf \{ %
\rm  %
\bf \} %
\rm  appear in the command form, then the modifiers
must appear within the braces.
{\it The} current implementation allows only one %
\bf : %
\rm  
{\it modifier} on each %
\bf \$ %
\rm  %
\it expansion%
\rm .
\par
The following substitutions may not be modified with %
\bf : %
\rm  modifiers.
\begin{TPlist}{\$?name}
\item[{\$?name}]
\nwl
\item[{\$\{?name\}}]
\nwl
Substitutes the string %
\bf 1 %
\rm  if name is set, %
\bf 0 %
\rm  if it is not.
\item[{\$?0}]
\nwl
Substitutes %
\bf 1 %
\rm  if the current input filename is known, %
\bf 0 %
\rm  if it is not.
\item[{\$\$}]
\nwl
Substitutes the decimal process number of the parent shell.
\item[{\$$<$}]
\nwl
Substitutes a line from the standard
input, with no further interpretation thereafter.  It can be used
to read from the keyboard in a shell script.
\sh{Command\ and\ filename\ substitution}
The remaining substitutions, command and filename substitutions,
are applied selectively to the arguments of builtin commands.
This means that portions of expressions that are not evaluated are
not subjected to these expansions.
For commands that are not internal to the shell, the command
name is substituted separately from the argument list.
This occurs very late,
after input-output redirection is performed, and in a child
of the main shell.
\sh{Command\ substitution}
Command substitution is indicated by a command enclosed in %
\bf %
\rm 's.
The output from such a command is normally broken into separate words
at blanks, tabs, and newlines, with null words being discarded;
this text then replaces the original string.
Within %
\bf "%
\rm 's, only newlines force new words; blanks and tabs are preserved.
\end{TPlist}
In any case, the single final newline does not force a new word.
Note that it is thus possible for a command substitution to yield
only part of a word, even if the command outputs a complete line.
\sh{Filename\ substitution}
If a word contains any of the characters  %
\bf *%
\rm , %
\bf ?%
\rm , %
\bf [%
\rm , %
\bf \{%
\rm ,
or begins with the character %
\bf \~{}%
\rm , then that word is a candidate for
filename substitution, also known as %
\bf globbing%
\rm .
This word is then regarded as a pattern, and replaced with an alphabetically
sorted list of filenames which match the pattern.
In a list of words specifying filename substitution, it is an error for
no pattern to match an existing filename, but it is not required
for each pattern to match.
Only the metacharacters %
\bf *%
\rm , %
\bf ?%
\rm , and %
\bf [ %
\rm  imply pattern matching,
the characters %
\bf \~{} %
\rm  and %
\bf \{ %
\rm  being more akin to abbreviations.
\par
In matching filenames, the %
\bf . %
\rm  at the beginning of a filename
or immediately following a %
\bf /%
\rm , as well as the %
\bf /%
\rm , must
be matched explicitly.
The %
\bf * %
\rm  matches any string of characters, including the null
string.
The %
\bf ? %
\rm  matches any single character.
The sequence %
\bf [...] %
\rm  matches any one of the characters enclosed.
Within %
\bf [...]%
\rm ,
a pair of characters separated by %
\bf -- %
\rm  matches any character lexically between
the two.
\par
The %
\bf \~{} %
\rm  at the beginning of a filename is used to refer to home
directories.
Standing alone, i.e. %
\bf \~{}%
\rm , it expands to the invoker%
\rm s home directory as reflected
in the value of the variable
{\it home.}
When followed by a name consisting of letters, digits, and %
\bf -- %
\rm  characters,
the shell searches for a user with that name and substitutes his
home directory.  Thus, %
\bf \~{}ken %
\rm  might expand to %
\bf /usr/ken %
\rm  and %
\bf \~{}ken/chmach %
\rm 
to %
\bf /usr/ken/chmach%
\rm .
If the %
\bf \~{} %
\rm  is followed by a character other than a letter or %
\bf /%
\rm ,
or appears other than at the beginning of a word,
it is left undisturbed.
\par
The metanotation %
\bf a\{b,c,d\}e %
\rm  is shorthand for %
\bf abe ace ade%
\rm .
Left-to-right order is preserved, with results of matches being sorted
separately at a low level to preserve this order.
This construct may be nested.  Thus, %
\bf \~{}source/s1/\{oldls,ls\}.c %
\rm  expands to
%
\bf /usr/source/s1/oldls.c /usr/source/s1/ls.c %
\rm 
(whether or not these files exist) without any chance of error,
if the home directory for %
\bf source %
\rm  is %
\bf /usr/source%
\rm .
Similarly, %
\bf ../\{memo,*box\} %
\rm  might expand to %
\bf ../memo ../box ../mbox%
\rm .
(Note that %
\bf memo %
\rm  was not sorted with the results of matching %
\bf *box%
\rm .)
As a special case, %
\bf \{%
\rm , %
\bf \}%
\rm , and %
\bf \{\} %
\rm  are passed undisturbed.
\sh{Input/output}
The standard input and standard output of a command may be redirected
with the following syntax:
\begin{TPlist}{$<$ name}
\item[{$<$ name}]
\nwl
Open file
{\it name}
(which is first variable, command, and filename expanded) as the standard
input.
\item[{$<$$<$ word}]
\nwl
Read the shell input up to a line which is identical to
{\it word.}
{\it Word}
is not subjected to variable, filename, or command substitution,
and each input line is compared to
{\it word}
before any substitutions are done on this input line.
Unless a quoting %
\bf \bs %
\rm , %
\bf "%
\rm , %
\bf %
\rm , or %
\bf  %
\rm  appears in
{\it word,}
variable and command substitution is performed on the intervening lines,
allowing %
\bf \bs  %
\rm  to quote %
\bf \$%
\rm , %
\bf \bs %
\rm , and %
\bf %
\rm .
Commands which are substituted have all blanks, tabs, and newlines
preserved, except for the final newline, which is dropped.
The resultant text is placed in an anonymous temporary file that
is given to the command as standard input.
\item[{$>$ name}]
\nwl
\item[{$>$! name}]
\nwl
\item[{$>$\& name}]
\nwl
\item[{$>$\&! name}]
\nwl
The file
{\it name}
is used as standard output.
If the file does not exist, then it is created;
if the file exists, it is truncated and its previous contents are lost.
\begin{itemize}
\item[{}]
If the variable
{\it noclobber}
is set, then the file must not exist or be a character special file (e.g. a
terminal or %
\bf /dev/null%
\rm ) or an error results.
This helps prevent accidental destruction of files.
In this case, the %
\bf ! %
\rm  forms can be used to suppress this check.
\item[{}]
The forms involving %
\bf \& %
\rm  route the diagnostic output into the specified
file as well as the standard output.
{\it Name}
is expanded in the same way that %
\bf $<$ %
\rm  input filenames are.
\end{itemize}%
\item[{$>$$>$ name}]
\nwl
\item[{$>$$>$\& name}]
\nwl
\item[{$>$$>$! name}]
\nwl
\item[{$>$$>$\&! name}]
\nwl
Uses file
{\it name}
as standard output, like %
\bf $>$%
\rm , but places output at the end of the file.
If the variable
{\it noclobber}
is set, then it is an error for the file not to exist unless
one of the %
\bf ! %
\rm  forms is given.
Otherwise similar to %
\bf $>$%
\rm .
\end{TPlist}
A command receives the environment in which the shell was
invoked as modified by the input-output parameters and
the presence of the command in a pipeline.
Thus, unlike some previous shells, commands that run from a file of shell commands
have no access to the text of the commands by default; rather,
they receive the original standard input of the shell.
The %
\bf $<$$<$ %
\rm  mechanism should be used to present inline data.
This permits shell command scripts to function as components of pipelines,
and allows the shell to block-read its input.
Note that the default standard input for a command run detached is
{\bf not}
modified to be the empty file %
\bf /dev/null%
\rm ; rather, the standard input
remains as the original standard input of the shell.  If this is a terminal
and if the process attempts to read from the terminal, then the process
will block and the user will be notified (see
{\bf Jobs}
above.)
\par
Diagnostic output may be directed through a pipe with the standard output.
Simply use the form %
\bf $|$\,\& %
\rm  rather than just %
\bf $|$%
\rm .
\sh{Expressions}
A number of the builtin commands, to be described subsequently,
take expressions, in which the operators are similar to those of C, with
the same precedence.
These expressions appear in the
{\it @,}
{\it exit,}
{\it if,}
and
{\it while}
commands.
The following operators are available:
%.DT
\par
	$|$\,\,$|$  \&\&  $|$    \&  ==  !=  =\~{}  !\~{}  $<$=  $>$=  $<$  $>$  $<$$<$  $>$$>$  +  --  *  /  \%  !  \~{}  (  )
\par
Here, the precedence increases to the right:
%
\bf ==%
\rm , %
\bf !=%
\rm , %
\bf =\~{}%
\rm , and %
\bf !\~{}%
\rm , %
\bf $<$=%
\rm , %
\bf $>$=%
\rm , %
\bf $<$%
\rm , and %
\bf $>$%
\rm , %
\bf $<$$<$ %
\rm  and %
\bf $>$$>$%
\rm , %
\bf + %
\rm  and %
\bf --%
\rm ,
%
\bf *%
\rm , %
\bf /%
\rm , and %
\bf \% %
\rm  being, in groups, at the same level.
The %
\bf ==%
\rm , %
\bf !=%
\rm , %
\bf =\~{}%
\rm , and %
\bf !\~{} %
\rm  operators compare their arguments as strings;
all others operate on numbers.
The operators %
\bf =\~{} %
\rm  and %
\bf !\~{} %
\rm  are like %
\bf != %
\rm  and %
\bf == %
\rm  except that the
right side is a
{\it pattern}
(containing, e.g. %
\bf *%
\rm , %
\bf ?%
\rm , and instances of %
\bf [...]%
\rm )
against which the left operand is matched.  This reduces the
need for use of the
{\it switch}
statement in shell scripts when all that is really needed is pattern matching.
\par
Strings that begin with %
\bf 0 %
\rm  are considered octal numbers.
Null or missing arguments are considered %
\bf 0%
\rm .
The result of all expressions are strings
that represent decimal numbers.
It is important to note that no two components of an expression can appear
in the same word; except when adjacent to components of expressions which
are syntactically significant to the parser (%
\bf \&%
\rm , %
\bf $|$%
\rm , %
\bf $<$%
\rm , %
\bf $>$%
\rm , %
\bf (%
\rm , and %
\bf )%
\rm ), they should be surrounded by spaces.
\par
Also available in expressions as primitive operands are command executions
enclosed in %
\bf \{ %
\rm  and %
\bf \} %
\rm 
and file enquiries of the form %
\bf --l name%
\rm , where
{\bf l}
is one of:
\par
%.DT
\nofill
	%
\bf r %
\rm 	read access
	%
\bf w %
\rm 	write access
	%
\bf x %
\rm 	execute access
	%
\bf e %
\rm 	existence
	%
\bf o %
\rm 	ownership
	%
\bf z %
\rm 	zero size
	%
\bf f %
\rm 	plain file
	%
\bf d %
\rm 	directory
\fill
\par
The specified name is command and filename expanded, and then tested
to see if it has the specified relationship to the real user.
If the file does not exist or is inaccessible, then all enquiries return
false, i.e. %
\bf 0%
\rm .
Command executions succeed, returning true, i.e. %
\bf 1%
\rm ,
if the command exits with status %
\bf 0%
\rm ; otherwise they fail, returning
false, i.e. %
\bf 0%
\rm .
If more detailed status information is required, then the command
should be executed outside of an expression and the variable
{\it status}
examined.
\sh{Control\ flow}
The shell contains a number of commands that can be used to regulate the
flow of control in command files shell scripts and,
in limited but useful ways, from terminal input.
These commands all operate by forcing the shell to reread or skip in its
input and, due to the implementation, restrict the placement of some
of the commands.
\par
The
{\it foreach,}
{\it switch,}
and
{\it while}
statements, as well as the
{\it if--then--else}
form of the
{\it if}
statement require that the major keywords appear in a single, simple command
on an input line, as shown below.
\par
If the shell%
\rm s input is not seekable,
the shell buffers up input whenever a loop is being read
and performs seeks in this internal buffer to accomplish the rereading
implied by the loop.
(To the extent that this allows, backward goto%
\rm s will succeed on
nonseekable inputs.)
\sh{Builtin\ commands}
Builtin commands are executed within the shell.
If a builtin command occurs as any component of a pipeline
except the last, it is executed in a subshell.
\begin{TPlist}{{\bf alias}}
\item[{{\bf alias}}]
\nwl
\item[{{\bf alias}{\rm \ name}
}]
\nwl
\item[{{\bf alias}{\rm \ name\ wordlist}
}]
\nwl
The first form prints all aliases.
The second form prints the alias for name.
The final form assigns the specified
{\it wordlist}
as the alias of 
{\it name;}
{\it wordlist}
is command and filename substituted.
{\it Name}
is not allowed to be
{\it alias}
or
{\it unalias.}
\item[{{\bf alloc}}]
\nwl
Shows the amount of dynamic core in use, broken down into used and
free core, and the address of the last location in the heap.
With an argument, it shows each used and free block on the internal dynamic
memory chain indicating its address, size, and whether it is used or free.
This is a debugging command and may not work in production versions of the
shell; it requires a modified version of the system memory allocator.
\item[{{\bf bg}}]
\nwl
\item[{%
\bf bg\ \%%
\rm job\ ...}]
\nwl
Puts the current or specified jobs into the background, continuing them
if they were stopped.
\item[{{\bf break}}]
\nwl
Causes execution to resume after the
{\it end}
of the nearest enclosing
{\it foreach}
or
{\it while.}
The remaining commands on the current line are executed.
Multi-level breaks are thus possible by writing them all on one line.
\item[{{\bf breaksw}}]
\nwl
Causes a break from a
{\it switch,}
resuming after the
{\it endsw.}
\item[{{\bf case}{\rm \ label:}
}]
\nwl
A label in a
{\it switch}
statement as discussed below.
\item[{{\bf cd}}]
\nwl
\item[{{\bf cd}{\rm \ name}
}]
\nwl
\item[{{\bf chdir}}]
\nwl
\item[{{\bf chdir}{\rm \ name}
}]
\nwl
Change the shell's working directory to directory
{\it name.}
If no argument is given, then change to the home directory of the user.
\nwl
If
{\it name}
is not found as a subdirectory of the current directory (and does not begin
with %
\bf /%
\rm , %
\bf ./%
\rm , or %
\bf ../%
\rm ), then each
component of the variable
{\it cdpath}
is checked to see if it has a subdirectory
{\it name.}
Finally, if all else fails, but
{\it name}
is a shell variable whose value begins with %
\bf /%
\rm , then this
is tried to see if it is a directory.
\item[{{\bf continue}}]
\nwl
Continue execution of the nearest enclosing
{\it while}
or
{\it foreach.}
The remaining commands on the current line are executed.
\item[{{\bf default:}}]
\nwl
Labels the default case in a
{\it switch}
statement.
The default should come after all
{\it case}
labels.
\item[{{\bf dirs}
}]
\nwl
Prints the directory stack; the top of the stack is at the left,
the first directory in the stack being the current directory.
\item[{{\bf echo}{\rm \ wordlist}
}]
\nwl
\item[{{\bf echo\ --n}{\rm \ wordlist}
}]
\nwl
The specified words are written to the shells standard output, separated
by spaces, and terminated with a newline, unless the
{\bf --n}
option is specified.
\item[{{\bf else}}]
\nwl
\item[{{\bf end}}]
\nwl
\item[{{\bf endif}}]
\nwl
\item[{{\bf endsw}}]
\nwl
See the description of the
{\it foreach,}
{\it if,}
{\it switch,}
and
{\it while}
statements below.
\item[{{\bf eval}{\rm \ arg\ ...}
}]
\nwl
(As in
{\it sh}{\rm (1).)}
The arguments are read as input to the shell and the resulting
command(s) executed in the context of the current shell.
This is usually used to execute commands
generated as the result of command or variable substitution, since
parsing occurs before these substitutions.  See
{\it tset}{\rm (1)}
for an example of using
{\it eval}{\rm .}
\item[{{\bf exec}{\rm \ command}
}]
\nwl
The specified command is executed in place of the current shell.
\item[{{\bf exit}}]
\nwl
\item[{{\bf exit}{\rm (expr)}
}]
\nwl
The shell exits either with the value of the
{\it status}
variable (first form) or with the value of the specified
{\it expr}
(second form).
\item[{{\bf fg}}]
\nwl
\item[{%
\bf fg\ \%%
\rm job\ ...}]
\nwl
Brings the current or specified jobs into the foreground, continuing them if
they were stopped.
\item[{{\bf foreach}{\rm \ name\ (wordlist)}
}]
\nwl
\item[{\    ...}]
\nwl
\item[{{\bf end}}]
\nwl
The variable
{\it name}
is successively set to each member of
{\it wordlist}
and the sequence of commands between this command and the matching
{\it end}
are executed.
(Both
{\it foreach}
and
{\it end}
must appear alone on separate lines.)
\begin{itemize}
\item[{}]
The builtin command
{\it continue}
may be used to continue the loop prematurely and the builtin
command
{\it break}
to terminate it prematurely.
When this command is read from the terminal, the loop is read up once
prompting with %
\bf ? %
\rm  before any statements in the loop are executed.
If you make a mistake entering in a loop at the terminal, you can rub it out.
\end{itemize}%
\item[{{\bf glob}{\rm \ wordlist}
}]
\nwl
%
\it Glob %
\rm  is like
{\it echo,}
but no %
\bf \bs  %
\rm  escapes are recognized and words are delimited
by null characters in the output.  This is
useful for programs that wish to use the shell to filename expand a list
of words.
\item[{{\bf goto}{\rm \ word}
}]
\nwl
The specified
{\it word}
is filename and command expanded to yield a string of the form %
\bf label%
\rm .
The shell rewinds its input as much as possible
and searches for a line of the form %
\bf label:%
\rm ,
possibly preceded by blanks or tabs.
Execution continues after the specified line.
\item[{{\bf hashstat}
}]
\nwl
Prints a statistics line indicating how effective the internal hash
table has been at locating commands and avoiding
{\it exec}{\rm %
\rm s.}
An
{\it exec}
is attempted for each component of the
{\it path,}
where the hash function indicates a possible hit, and in each component
that does not begin with a %
\bf /%
\rm .
\item[{{\bf history}}]
\nwl
\item[{{\bf history}{\it \ n}
}]
\nwl
\item[{{\bf history\ --r}{\it \ n}
}]
\nwl
\item[{{\bf history\ --h}{\it \ n}
}]
\nwl
Displays the history event list; if %
\it n %
\rm  is given, only the
{\it n}
most recent events are printed.
The
{\bf --r}
option reverses the order of printout to be most recent first.
The
{\bf --h}
option causes the history list to be printed without leading numbers.
This is used to produce files suitable for sourcing using the %
\bf --h %
\rm 
option to
{\it source}{\rm .}
\item[{{\bf if}{\rm \ (expr)\ command}
}]
\nwl
If the specified expression evaluates true, then the single
{\it command}
with arguments is executed.
Variable substitution on
{\it command}{\rm }
happens early, at the same
time it does for the remaining
{\it if}
command.
{\it Command}
must be a simple command, not
a pipeline, a command list, or a parenthesized command list.
Input/output redirection occurs even if
{\it expr}
is false, when command is
{\it not}
executed (this is a bug).
\item[{{\bf if}{\rm \ (expr)\ }{\bf then}
}]
\nwl
\item[{\    ...}]
\nwl
\item[{{\bf else} if}]
 %
\rm  (expr2) %
\bf then"
\nwl
\item[{\    ...}]
\nwl
\item[{{\bf else}}]
\nwl
\item[{\    ...}]
\nwl
\item[{{\bf endif}}]
\nwl
If the specified
{\it expr}{\rm }
is true, then the commands to the first
{\it else}
are executed; %
\bf else if %
\rm 
{\it expr2}{\rm }
is true then the commands to the
second else are executed, etc.
Any number of pairs are possible; only one
{\bf endif}
is needed.
The
{\bf else}
part is likewise optional.
(The words
{\bf else}
and
{\bf endif}
must appear at the beginning of input lines;
the
{\bf if}
must appear alone on its input line or after an
{\bf else.)}
\item[{{\bf jobs}}]
\nwl
\item[{{\bf jobs\ --l}}]
\nwl
Lists the active jobs; given the
{\bf --l}
options lists process ID's in addition to the normal information.
\item[{%
\bf kill \%%
\rm job}]
\nwl
\item[{%
\bf kill\ --%
\rm sig\ %
\bf \%%
\rm job\ ...}]
\nwl
\item[{%
\bf kill%
\rm \ pid}]
\nwl
\item[{%
\bf kill\ --%
\rm sig\ pid\ ...}]
\nwl
\item[{%
\bf kill\ --l%
\rm }]
\nwl
Sends either the TERM (terminate) signal or the
specified signal to the specified jobs or processes.
Signals are either given by number or by names (as given in
{\it /usr/include/signal.h,}
stripped of the prefix %
\bf %
\bf SIG%
\rm %
\rm ).
The signal names are listed by %
\bf kill --l%
\rm .
There is no default, entering %
\bf kill %
\rm  does not
send a signal to the current job.
If the signal being sent is TERM (terminate) or HUP (hangup),
then the job or process will be sent a CONT (continue) signal as well.
\item[{%
\bf limit%
\rm }]
\nwl
\item[{%
\bf limit%
\rm }]
resource
\nwl
\item[{%
\bf limit%
\rm }]
resource maximum-use
\nwl
Limits the consumption by the current process and each process
it creates to not individually exceed %
\it maximum-use %
\rm  on the
specified %
\it resource%
\rm .  If no %
\it maximum-use %
\rm  is given, then
the current limit is printed; if no %
\it resource %
\rm  is given, then
all limitations are given.
\begin{itemize}
\item[{}]
Resources that are controllable currently include %
\it cputime %
\rm  (the maximum
number of cpu-seconds to be used by each process), %
\it filesize %
\rm 
(the largest single file which can be created), %
\it datasize %
\rm 
(the maximum growth of the data+stack region via
{\it sbrk}{\rm (2)}
beyond the end of the program text), %
\it stacksize %
\rm  (the maximum
size of the automatically-extended stack region), %
\it coredumpsize %
\rm 
(the size of the largest core dump that will be created), and %
\it memoryuse %
\rm 
(the maximum size a process%
\rm s resident set size may grow to).
\item[{}]
The %
\it maximum-use %
\rm  may be given as a floating-point or integer
number followed by a scale factor.  For all limits other than %
\it cputime %
\rm 
the default scale is %
\bf k %
\rm  or %
\bf kilobytes %
\rm  (1024 bytes);
a scale factor of %
\bf m %
\rm  or %
\bf megabytes %
\rm  may also be used.
For
{\it cputime,}
the default scaling is %
\bf seconds%
\rm , while %
\bf m %
\rm  for minutes
or %
\bf h %
\rm  for hours, or a time of the form `mm:ss' giving minutes
and seconds may be used.
\item[{}]
For both %
\it resource %
\rm  names and scale factors, unambiguous prefixes
of the names suffice.
\end{itemize}%
\item[{{\bf login}}]
\nwl
Terminate a login shell, replacing it with an instance of
{\bf /bin/login.}
This is one way to log off (included for compatibility with
{\it sh}{\rm (1)).}
\item[{{\bf logout}}]
\nwl
Terminate a login shell.
Especially useful if
{\it ignoreeof}
is set.
\item[{{\bf nice}}]
\nwl
\item[{{\bf nice}{\rm \ number}
}]
\nwl
\item[{{\bf nice}{\rm \ command}
}]
\nwl
\item[{{\bf nice}{\rm \ number\ command}
}]
\nwl
The first form sets the
{\it nice}
for this shell to 4.
The second form sets the
{\it nice}
to the given number.
The final two forms run command at priority 4 and
{\it number}
respectively.
The superuser may specify negative niceness by using %
\bf nice%
\rm -number ....
Command is always executed in a subshell, and the restrictions
placed on commands in simple
{\it if}
statements apply.
\item[{{\bf nohup}}]
\nwl
\item[{{\bf nohup}{\rm \ command}
}]
\nwl
The first form can be used in shell scripts to cause hangups to be
ignored for the remainder of the script.
The second form causes the specified command to be run with hangups
ignored.
All processes detached with %
\bf \& %
\rm  are effectively
{\it nohup%
\rm ed.}
\item[{{\bf notify}}]
\nwl
\item[{%
\bf notify\ \%%
\rm job\ ...}]
\nwl
Causes the shell to notify the user asynchronously when the status of the
current or specified jobs changes; normally notification is presented
before a prompt.  This is automatic if the shell variable
{\it notify}
is set.
\item[{{\bf onintr}}]
\nwl
\item[{{\bf onintr}{\rm \ \ --}
}]
\nwl
\item[{{\bf onintr}{\rm \ \ label}
}]
\nwl
Control the action of the shell on interrupts.
The first form restores the default action of the shell on interrupts
that are to terminate shell scripts or to return to the terminal command
input level.
The second form %
\bf onintr -- %
\rm  causes all interrupts to be ignored.
The final form causes the shell to execute a %
\bf goto label %
\rm  when
an interrupt is received or a child process terminates because
it was interrupted.
\begin{itemize}
\item[{}]
In any case, if the shell is running detached and interrupts are
being ignored, all forms of
{\it onintr}
have no meaning, and interrupts
continue to be ignored by the shell and all invoked commands.
\end{itemize}%
\item[{{\bf popd}
}]
\nwl
\item[{{\bf popd}{\rm \ +n}
}]
\nwl
Pops the directory stack, returning to the new top directory.
With an argument %
\bf +%
\it n%
\rm  %
\rm  discards the %
\it n%
\rm \,th
entry in the stack.
The elements of the directory stack are numbered from 0 starting at the top.
\item[{{\bf pushd}
}]
\nwl
\item[{{\bf pushd}{\rm \ name}
}]
\nwl
\item[{{\bf pushd}{\rm \ +n}
}]
\nwl
With no arguments,
{\it pushd}
exchanges the top two elements of the directory stack.
Given a
{\it name}
argument,
{\it pushd}
changes to the new directory (ala
{\it cd)}
and pushes the old current working directory
(as in
{\it csw)}
onto the directory stack.
With a numeric argument, rotates the %
\it n%
\rm \,th argument of the directory
stack around to be the top element and changes to it.  The members
of the directory stack are numbered from the top starting at 0.
\item[{{\bf rehash}
}]
\nwl
Causes the internal hash table of the contents of the directories in
the
{\it path}
variable to be recomputed.  This is needed if new commands are added
to directories in the
{\it path}
while you are logged in.  This should only be necessary if you add
commands to one of your own directories, or if a systems programmer
changes the contents of one of the system directories.
\item[{{\bf repeat}{\rm \ count\ command}
}]
\nwl
The specified 
{\it command,}
which is subject to the same restrictions
as the
{\it command}
in the one line
{\it if}
statement above,
is executed
{\it count}
times.
I/O redirections occur exactly once, even if
{\it count}
is 0.
\item[{{\bf set}}]
\nwl
\item[{{\bf set}{\rm \ name}
}]
\nwl
\item[{{\bf set}{\rm \ name=word}
}]
\nwl
\item[{{\bf set}{\rm \ name[index]=word}
}]
\nwl
\item[{{\bf set}{\rm \ name=(wordlist)}
}]
\nwl
The first form of the command shows the value of all shell variables.
Variables which have other than a single word as value print as a parenthesized
word list.
The second form sets
{\it name}
to the null string.
The third form sets
{\it name}
to the single
{\it word.}
The fourth form sets
the
{\it index%
\rm th}
component of name to word;
this component must already exist.
The final form sets
{\it name}
to the list of words in
{\it wordlist.}
In all cases, the value is command and filename expanded.
\begin{itemize}
\item[{}]
These arguments may be repeated to set multiple values in a single set command.
Note however, that variable expansion happens for all arguments before any
setting occurs.
\end{itemize}%
\item[{{\bf setenv}{\rm \ name\ value}
}]
\nwl
Sets the value of environment variable
{\it name}
to be
{\it value,}
a single string.
The most commonly used environment variable USER, TERM, and PATH
are automatically imported to and exported from the
{\it csh}
variables
{\it user,}
{\it term,}
and
{\it path;}
there is no need to use
{\it setenv}
for these.
\item[{{\bf shift}}]
\nwl
\item[{{\bf shift}{\rm \ variable}
}]
\nwl
The members of
{\it argv}
are shifted to the left, discarding
{\it argv[1].}
It is an error for
{\it argv}
not to be set or to have less than one word as value.
The second form performs the same function on the specified variable.
\item[{{\bf source}{\rm \ name}
}]
\nwl
\item[{{\bf source\ --h}{\rm \ name}
}]
\nwl
The shell reads commands from
{\it name.}
{\it Source}
commands may be nested; if they are nested too deeply, the shell may
run out of file descriptors.
An error in a
{\it source}
at any level terminates all nested
{\it source}
commands.
Normally, input during 
{\it source}
commands is not placed on the history list;
the %
\bf --h %
\rm  option causes the commands to be placed in the
history list without being executed.
\item[{{\bf stop}}]
\nwl
\item[{%
\bf stop\ \%%
\rm job\ ...}]
\nwl
Stops the current or specified job that is executing in the background.
\item[{{\bf suspend}}]
\nwl
Causes the shell to stop in its tracks, much as if it had been sent a stop
signal with %
\bf \^{}Z%
\rm .  This is most often used to stop shells started by
{\it su}{\rm (1).}
\item[{{\bf switch}{\rm \ (string)}
}]
\nwl
\item[{{\bf case}{\rm \ str1:}
}]
\nwl
\item[{\    ...}]
\nwl
\item[{\   }]
{\bf breaksw}
\nwl
\item[{...}]
\nwl
\item[{{\bf default:}}]
\nwl
\item[{\    ...}]
\nwl
\item[{\   }]
{\bf breaksw}
\nwl
\item[{{\bf endsw}}]
\nwl
Each case label is successively matched against the specified
{\it string}
(which is first command and filename expanded).
The file metacharacters %
\bf *%
\rm , %
\bf ?%
\rm , and %
\bf [...] %
\rm  may be used in the case labels,
which are variable expanded.
If none of the labels match before a %
\bf default %
\rm  label is found, then
the execution begins after the default label.
Each case label and the default label must appear at the beginning of a line.
The command 
{\it breaksw}
causes execution to continue after the
{\it endsw.}
Otherwise, control may fall through case labels and default labels as in C.
If no label matches and there is no default, execution continues after
the
{\it endsw.}
\item[{{\bf time}}]
\nwl
\item[{{\bf time}{\rm \ command}
}]
\nwl
With no argument, a summary of time used by this shell and its children
is printed.
If arguments are given,
the specified simple command is timed and a time summary,
as described under the
{\it time}
variable, is printed.  If necessary, an extra shell is created to print the time
statistic when the command completes.
\item[{{\bf umask}}]
\nwl
\item[{{\bf umask}{\rm \ value}
}]
\nwl
The file creation mask is displayed (first form) or set to the specified
value (second form).  The mask is given in octal.  Common values for
the mask are 002, giving all access to the group and read and execute
access to others, or 022, giving yourself all access, but no write access for
users in the group or others.
\item[{{\bf unalias}{\rm \ pattern}
}]
\nwl
All aliases whose names match the specified pattern are discarded.
Thus, all aliases are removed by %
\bf unalias *%
\rm .
It is not an error if nothing is
{\it unaliased.}
\item[{{\bf unhash}
}]
\nwl
Use of the internal hash table to speed location of executed programs
is disabled.
\item[{%
\bf unlimit %
\rm  resource}]
\nwl
\item[{%
\bf unlimit%
\rm }]
\nwl
Removes the limitation on %
\it resource%
\rm .  If no %
\it resource %
\rm 
is specified, then all %
\it resource %
\rm  limitations are removed.
\item[{{\bf unset}{\rm \ pattern}
}]
\nwl
All variables whose names match the specified pattern are removed.
Thus, all variables are removed by %
\bf unset *%
\rm ; this has noticeably
distasteful side effects.
It is not an error for nothing to be
{\it unset.}
\item[{{\bf unsetenv}{\rm \ pattern}
}]
\nwl
Removes all variables whose names match the specified pattern from the
environment.  See the
{\it setenv}
command above and
{\it printenv}{\rm (1).}
\item[{{\bf wait}}]
\nwl
All background jobs are waited for.
If the shell is interactive, then an interrupt can disrupt the wait,
at which time the shell prints names and job numbers of all jobs
known to be outstanding.
\item[{{\bf while}{\rm \ (expr)}
}]
\nwl
\item[{\    ...}]
\nwl
\item[{{\bf end}}]
\nwl
While the specified expression evaluates nonzero, the commands between
the
{\it while}
and the matching end are evaluated.
{\it Break}
and
{\it continue}
may be used to terminate or continue the loop prematurely.
(The
{\it while}
and
{\it end}
must appear alone on their input lines.)
Prompting occurs here, for the first time, through the loop as for the
{\it foreach}
statement if the input is a terminal.
\item[{%
\bf \%%
\rm job}]
\nwl
Brings the specified job into the foreground.
\item[{%
\bf \%%
\rm job %
\bf \&%
\rm }]
\nwl
Continues the specified job in the background.
\item[{{\bf @}}]
\nwl
\item[{{\bf @}{\rm \ name\ =\ expr}
}]
\nwl
\item[{{\bf @}{\rm \ name[index]\ =\ expr}
}]
\nwl
The first form prints the values of all the shell variables.
The second form sets the specified
{\it name}
to the value of
{\it expr.}
If the expression contains %
\bf $<$%
\rm , %
\bf $>$%
\rm , %
\bf \&%
\rm , or %
\bf $|$%
\rm , then at least
part of the expression must be placed within %
\bf ( %
\rm  %
\bf )%
\rm .
The third form assigns the value of
{\it expr}
to the
{\it index%
\rm th}
argument of
{\it name.}
Both 
{\it name}
and its
{\it index%
\rm th}
component must already exist.
\begin{itemize}
\item[{}]
The operators %
\bf *=%
\rm , %
\bf +=%
\rm , etc. are available as in C.
The space separating the name from the assignment operator is optional.
Spaces, however, are mandatory in separating components of
{\it expr}
that would otherwise be single words.
\item[{}]
Special postfix %
\bf ++ %
\rm  and %
\bf --\,-- %
\rm  operators increment and decrement
{\it name}
respectively, i.e. %
\bf @i++%
\rm .
\sh{Predefined\ and\ environment\ variables}
The following variables have special meaning to the shell.
Of these,
{\it argv,}
{\it autologout,}
{\it cwd,}
{\it home,}
{\it path,}
{\it prompt,}
{\it shell,}
and
{\it status}
are always set by the shell.
Except for
{\it cwd}
and
{\it status,}
this setting occurs only at initialization;
these variables will not be modified unless this is done
explicitly by the user.
\end{itemize}\end{TPlist}
This shell copies the environment variable USER into the variable
{\it user,}
TERM into
{\it term,}
and
HOME into
{\it home,}
and copies these back into the environment whenever the normal
shell variables are reset.
The environment variable PATH is likewise handled.  It is not
necessary to worry about its setting other than in the file
{\it .cshrc,}
as inferior
{\it csh}
processes will import the definition of
{\it path}
from the environment, and re-export it if you change it.
\begin{TPlist}{{\bf argv}}
\item[{{\bf argv}}]

Set to the arguments to the shell, it is from this variable that
positional parameters are substituted, i.e. %
\bf \$1 %
\rm  is replaced by
%
\bf \$argv[1]%
\rm , etc.
\item[{{\bf autologout}}]

Set to the number of minutes an interactive
shell can be idle before the shell automatically terminates itself.
The default value for
{\it autologout}
is 0;
{\it autologout}
disabled.
For the shell, idle time is defined to be the time between when the
{\it prompt}
is printed and when a command is entered.
The
{\it autologout}
feature is disabled by setting its value to 0.
\item[{{\bf cdpath}}]

Gives a list of alternate directories searched to find subdirectories
in
{\it chdir}
commands.
\item[{{\bf cwd}}]
The full pathname of the current directory.
\item[{{\bf echo}}]

Set when the
{\bf --x}
command line option is given.
Causes each command and its arguments
to be echoed just before it is executed.
For non-builtin commands, all expansions occur before echoing.
Builtin commands are echoed before command and filename substitution,
since these substitutions are done selectively.
\item[{{\bf histchars}}]

Can be given a string value to change the characters used in history
substitution.  The first character of its value is used as the
history substitution character, replacing the default character %
\bf !%
\rm .
The second character of its value replaces the character %
\bf  %
\rm  in
quick substitutions.
\item[{{\bf history}}]

Can be given a numeric value to control the size of the history list.
Any command which has been referenced in this many events will not be
discarded.
Too large values of
{\it history}
may run the shell out of memory.
The last executed command is always saved on the history list.
\item[{{\bf home}}]

The home directory of the invoker, initialized from the environment.
The filename expansion of %
\bf %
\bf \~{}%
\rm  %
\rm  refers to this variable.
\item[{{\bf ignoreeof}}]

If set, the shell ignores
end-of-file from input devices that are terminals.
This prevents shells from accidentally being killed by %
\bf \^{}D%
\rm 's.
\item[{{\bf mail}}]

The files where the shell checks for mail.
This is done after each command completion that will result in a prompt,
if a specified interval has elapsed.
The shell says %
\bf You have new mail%
\rm ,
if the file exists with an access time not greater than its modify time.
\begin{itemize}
\item[{}]
If the first word of the value of
{\it mail}
is numeric, it specifies a different mail checking interval, in seconds,
than the default, which is 10 minutes.
\item[{}]
If multiple mail files are specified, then the shell says
%
\bf New mail in
{\it name}{\rm %
\rm }
when there is mail in the file
{\it name.}
\end{itemize}%
\item[{{\bf noclobber}}]

As described in the section on
{\bf Input/output,}
restrictions are placed on output redirection to ensure that
files are not accidentally destroyed, and that %
\bf $>$$>$ %
\rm  redirections
refer to existing files.
\item[{{\bf noglob}}]

If set, filename expansion is inhibited.
This is most useful in shell scripts which are not dealing with filenames,
or after a list of filenames has been obtained and further expansions
are not desirable.
\item[{{\bf nonomatch}}]

If set, it is not an error for a filename expansion to not match any
existing files; rather the primitive pattern is returned.
It is still an error for the primitive pattern to be malformed, i.e.
%
\bf echo [ %
\rm  still gives an error.
\item[{{\bf notify}}]

If set, the shell notifies asynchronously of job completions.  The
default is to present job completions just before printing
a prompt.
\item[{{\bf path}}]

Each word of the path variable specifies a directory in which
commands are to be sought for execution.
A null word specifies the current directory.
If there is no
{\it path}
variable, then only full path names will execute.
The usual search path is %
\bf .%
\rm , 
{\it /bin,}
and 
{\it /usr/bin,} 
but this
may vary from system to system.
For the superuser, the default search path is 
{\it /etc,} /bin,
and 
{\it /usr/bin.}
A shell which is given neither the
{\bf --c}
nor the
{\bf --t}
option will normally hash the contents of the directories in the
{\it path}
variable after reading
{\it .cshrc,}
and each time the
{\it path}
variable is reset.  If new commands are added to these directories
while the shell is active, it may be necessary to give the
{\it rehash}
or the commands may not be found.
\item[{{\bf prompt}}]

The string which is printed before each command is read from
an interactive terminal input.
If a %
\bf ! %
\rm  appears in the string, it will be replaced by the current event number
unless a preceding %
\bf \bs  %
\rm  is given.
Default is %
\bf \% %
\rm , or %
\bf \#  %
\rm  for the superuser.
\item[{{\bf savehist}}]

is given a numeric value to control the number of entries of the
history list that are saved in
{\it \~{}/.history} 
when the user logs out.
Any command which has been referenced in this many events will be saved.
During start-up, the shell sources 
{\it \~{}/.history} 
into the history list
enabling history to be saved across logins.
Too large values of
{\it savehist}
will slow down the shell during start up.
\item[{{\bf shell}}]

The file in which the shell resides.
This is used in forking shells to interpret files which have execute
bits set, but which are not executable by the system.
(See the description of
{\bf Non-builtin} Command Execution
below.)
Initialized to the system-dependent home of the shell.
\item[{{\bf status}}]

The status returned by the last command.
If it terminated abnormally, then 0200 is added to the status.
Builtin commands which fail return exit status %
\bf 1%
\rm ;
all other builtin commands set status %
\bf 0%
\rm .
\item[{{\bf time}}]

Controls automatic timing of commands.
If set, then any command which takes more than this many CPU seconds
will cause a line to be printed that gives
user, system, and real times, and a utilization
percentage, which is the ratio of user plus system times to real time.
\item[{{\bf verbose}}]

Set by the
{\bf --v}
command line option, this causes the words of each command to be printed
after history substitution.
\sh{Non-builtin\ command\ execution}
When a command to be executed is not a builtin command,
the shell attempts to execute the command via
{\it execve}{\rm (2).}
Each word in the variable
{\it path}
names a directory from which the shell will attempt to execute the command.
If it is given neither a
{\bf --c}
nor a
{\bf --t}
option, the shell will hash the names in these directories into an internal
table so that it will only try an
{\it exec}
in a directory if there is a possibility that the command resides there.
This greatly speeds command location when a large number of directories
are present in the search path.
If this mechanism has been turned off (via
{\it unhash}{\rm ),}
or if the shell was given a
{\bf --c}
or
{\bf --t}
argument, and in any case for each directory component of
{\it path}
that does not begin with a %
\bf /%
\rm ,
the shell concatenates with the given command name to form a path name
of a file which it then attempts to execute.
\end{TPlist}
Parenthesized commands are always executed in a subshell.
Thus %
\bf (cd ; pwd) ; pwd %
\rm  prints the
{\it home}
directory; leaving you where you were (printing this after the home directory),
while %
\bf cd ; pwd %
\rm  leaves you in the
{\it home}
directory.
Parenthesized commands are most often used to prevent
{\it chdir}
from affecting the current shell.
\par
If the file has execute permissions, but is not an
executable binary to the system, then it is assumed to be a
file containing shell commands and a new shell is spawned to read it.
\par
If there is an
{\it alias}
for
{\it shell,}
then the words of the alias will be prepended to the argument list to form
the shell command.
The first word of the
{\it alias}
should be the full path name of the shell
(e.g. %
\bf \$shell%
\rm ).
Note that this is a special, late occurring, case of
{\it alias}
substitution,
and only allows words to be prepended to the argument list without modification.
\sh{Argument\ list\ processing}
If argument 0 to the shell is %
\bf --%
\rm , then this
is a login shell.
The flag arguments are interpreted as follows:
\begin{TPlist}{{\bf --c}}
\item[{{\bf --c}}]

Commands are read from the single following argument which must
be present.
Any remaining arguments are placed in
{\it argv.}
\item[{{\bf --e}}]

The shell exits if any invoked command terminates abnormally
or yields a nonzero exit status.
\item[{{\bf --f}}]

The shell will start faster, because it will neither search for, nor
execute commands from the file
%
\it .cshrc %
\rm  in the invoker's home directory.
\item[{{\bf --i}}]

The shell is interactive and prompts for its top-level input,
even if it appears to not be a terminal.
Shells are interactive without this option if their inputs
and outputs are terminals.
\item[{{\bf --n}}]

Commands are parsed, but not executed.
This aids in syntactic checking of shell scripts.
\item[{{\bf --s}}]

Command input is taken from the standard input.
\item[{{\bf --t}}]

A single line of input is read and executed.
A %
\bf \bs  %
\rm  may be used to escape the newline at the end of this
line and continue onto another line.
\item[{{\bf --v}}]

Causes the
{\it verbose}
variable to be set, with the effect
that command input is echoed after history substitution.
\item[{{\bf --x}}]

Causes the 
{\it echo}
variable to be set, so that commands are echoed immediately before execution.
\item[{{\bf --V}}]

Causes the
{\it verbose}
variable to be set even before %
\it .cshrc %
\rm  is executed.
\item[{{\bf --X}}]

Is to
{\bf --x}
as
{\bf --V}
is to
{\bf --v.}
\end{TPlist}
After processing of flag arguments, if arguments remain but none of the
{\bf --c,}
{\bf --i,}
{\bf --s,}
or
{\bf --t}
options were given, the first argument is taken as the name of a file of
commands to be executed.
The shell opens this file, and saves its name for possible resubstitution
by %
\bf \$0%
\rm .
Since many systems use either the standard version 6 or version 7 shells
whose shell scripts are not compatible with this shell, the shell will
execute such a %
\bf standard %
\rm  shell if the first character of a script
is not a %
\bf \#%
\rm , i.e. if the script does not start with a comment.
Remaining arguments initialize the variable
{\it argv.}
\sh{Signal\ handling}
The shell normally ignores
{\it quit}
signals.
Jobs running detached (either by %
\bf \&%
\rm , %
\bf bg%
\rm , or %
\bf \%... \& %
\rm 
commands) are immune to signals generated from the keyboard, including
hangups.
Other signals have the values which the shell inherited from its parent.
The shells handling of interrupts and terminate signals
in shell scripts can be controlled by
{\it onintr.}
Login shells catch the
{\it terminate}
signal; otherwise, this signal is passed on to children from the state in the
shell%
\rm s parent.
In no case, are interrupts allowed when a login shell is reading the file
%
\it .logout%
\rm .
\shead{AUTHOR}
William Joy.
Job control and directory stack features first implemented by J. E. Kulp of
I.I.A.S.A, Laxenburg, Austria,
with different syntax than is used now.
\shead{FILES}
%.ta 1.75i
\nofill
\~{}/.cshrc	Read at beginning of execution by each shell.
\~{}/.login	Read by login shell, after %
\it .cshrc %
\rm  at login.
\~{}/.logout	Read by login shell, at logout.
/bin/sh	Standard shell, for shell scripts not starting with a %
\bf \#%
\rm .
/tmp/sh*	Temporary file for %
\bf $<$$<$%
\rm .
/etc/passwd	Source of home directories for %
\bf \~{}name%
\rm .
\fill
\shead{LIMITATIONS}
Words can be no longer than 1024 characters.
The system limits argument lists to 10240 characters.
The number of arguments to a command, which involves filename expansion,
is limited to 1/6 the number of characters allowed in an argument list.
Command substitutions may substitute no more characters than are
allowed in an argument list.
To detect looping, the shell restricts the number of
{\it alias}
substitutions on a single line to 20.
\shead{SEE ALSO}
sh(1), access(2), execve(2), fork(2), killpg(2), pipe(2), sigvec(2),
umask(2), getrlimit(2), wait(2), tty(4), a.out(5), environ(7)
\par
``An introduction to the C shell'' in the %
\it CONVEX UNIX Tutorial Papers %
\rm 
\shead{BUGS}
When a command is restarted from a stop,
the shell prints the directory it started in, if this is different
from the current directory.  This can be misleading (i.e. wrong)
as the job may have changed directories internally.
\par
Shell builtin functions are not stoppable/restartable.
Command sequences of the form %
\bf a ; b ; c %
\rm  are also not handled gracefully
when stopping is attempted.  If you suspend %
\bf b%
\rm , the shell will
immediately execute %
\bf c%
\rm .  This is especially noticeable if this
expansion results from an
{\it alias.}
It suffices to place the sequence of commands in %
\bf ( ) %
\rm  to force it to
a subshell, i.e. %
\bf ( a ; b ; c )%
\rm .
\par
Control over tty output after processes are started is primitive;
perhaps this will inspire someone to work on a good virtual
terminal interface.  In a virtual terminal interface, much more
interesting things could be done with output control.
\par
Alias substitution is most often used to clumsily simulate shell procedures;
shell procedures should be provided rather than aliases.
\par
Commands within loops, prompted for by %
\bf ?%
\rm , are not placed in the
{\it history}
list.
Control structure should be parsed rather than being recognized as builtin
commands.  This would allow control commands to be placed anywhere,
to be combined with %
\bf $|$%
\rm , and to be used with %
\bf \& %
\rm  and %
\bf ; %
\rm  metasyntax.
\par
It should be possible to use the %
\bf : %
\rm  modifiers on the output of command
substitutions.
All and more than one %
\bf : %
\rm  modifier should be allowed on %
\bf \$ %
\rm  substitutions.
\par
Symbolic links fool the shell.  In particular,
{\bf dirs}
and %
\bf cd .. %
\rm  do not work properly once you have crossed through a symbolic
link.
\end{document}
