csh(1) INTERACTIVE UNIX System csh(1)
NAME
csh - invoke a shell command interpreter that uses C-like
syntax
SYNOPSIS
csh [ -cefinstvVxX ] [ arg ... ]
DESCRIPTION
csh is a command language interpreter. It begins by execut-
ing commands from the file .cshrc in the home directory of
the invoker. If this is a login shell, then it also exe-
cutes commands from the user's .login file. In the normal
case, the shell will then begin reading commands from the
terminal, prompting with %. Processing of arguments and the
use of the shell to process files containing command scripts
will be described later.
The shell then repeatedly performs the following actions: a
line of command input is read and broken into words. This
sequence of words is placed on the command history list and
then parsed. Finally, each command in the current line is
executed.
When a login shell terminates, it executes commands from the
file .logout in the user's home directory.
Lexical Structure
The shell splits input lines into words at blanks and tabs
with the following exceptions. The characters &, |, ;, <,
>, (, and ) form separate words. If doubled (for example,
&&, ||, <<, or >>) these character pairs form single words.
These parser metacharacters may be made part of other words,
or you can take away their special meaning by preceding them
with a backslash character (\). A new-line character pre-
ceded by a \ is equivalent to a blank.
Strings enclosed in matched pairs of quotations, ', `, or ",
form parts of a word; metacharacters in these strings,
including blanks and tabs, do not form separate words. The
semantics of these quotations are described below. Within
pairs of ' or " characters, a new-line character preceded by
a \ gives a true new-line character.
When the shell's input is not from a terminal, the character
# introduces a comment which continues to the end of the
input line. It does not have this special meaning when pre-
ceded by \ or when placed inside the quotation marks `, ',
and ".
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 | characters forms
Rev. 1.3 Page 1
csh(1) INTERACTIVE UNIX System csh(1)
a pipeline. The output of each command in a pipeline pro-
vides the input for the next command. Sequences of pipe-
lines may be executed sequentially by separating them with
the ; character. A sequence of pipelines may be executed in
the background by following it with the & character.
Any of the above may be placed in parentheses to form a sim-
ple command, which may be a component of a pipeline, etc.
It is also possible to separate pipelines with || or &&
indicating, as in the C language, that the second is to be
executed only if the first fails or succeeds respectively.
(See Expressions.)
Jobs
The shell associates a job with each pipeline. It keeps a
table of current jobs, printed by the jobs command, and
assigns them small integer numbers. When a job is started
asynchronously with &, the shell prints a line that looks
like:
[1] 1234
indicating that the job that was started asynchronously was
job number 1 and it had one (top-level) process, whose pro-
cess ID was 1234.
If you are running a job and wish to do something else, you
may use ^Z (CTRL-Z) which sends a STOP signal to the current
job. The shell will then 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 back-
ground with the bg command, or run some other commands and
then eventually bring the job back into the foreground with
the foreground command fg. A ^Z takes effect immediately
and is like an interrupt in that pending output and unread
input are discarded when it is typed. There is another spe-
cial key, ^Y, which does not generate a STOP signal until a
program attempts to read(2) it. This can usefully be typed
ahead when you have prepared some commands for a job that
you wish to stop after it has read them.
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 giv-
ing the command ``stty tostop.'' If you set this terminal
option, then background jobs will stop when they try to pro-
duce output as they do when they try to read input.
There are several ways to refer to jobs in the shell. The
character % introduces a job name. If you wish to refer to
job number 1, you can name it as %1. Just naming a job
brings it to the foreground; thus %1 is a synonym for fg %1,
bringing job 1 back into the foreground. Similarly, saying
Rev. 1.3 Page 2
csh(1) INTERACTIVE UNIX System csh(1)
%1& 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 %ex would normally restart a
suspended ex(1) job, if there were only one suspended job
whose name began with the string ex. It is also possible to
say %? string which specifies a job whose text contains
string, if there is only one such job.
The shell maintains a notion of the current and previous
jobs. In output pertaining to jobs, the current job is
marked with a + and the previous job with a -. The abbrevi-
ation %+ refers to the current job and %- refers to the pre-
vious job. For close analogy with the syntax of the history
mechanism (described below), %% is also a synonym for the
current job.
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 notify, the shell will notify you immedi-
ately of changes of status in background jobs. There is
also a shell command notify which marks a single process so
that its status changes will be immediately reported. By
default notify marks the current process; simply say notify
after starting a background job to mark it.
When you try to leave the shell while jobs are stopped, you
will be warned that ``You have stopped jobs.'' You may use
the jobs command to see what they are. If you do this or
immediately try to exit again, the shell will not warn you a
second time, and the suspended jobs will be terminated.
Substitutions
The following sections describe the various transformations
the shell performs on the input in the order in which they
occur.
History Substitutions
History substitutions can be used to reintroduce sequences
of words from previous commands, possibly performing modifi-
cations on these words. Thus, history substitutions provide
a generalization of a redo function.
History substitutions begin with the ! character and may
begin anywhere in the input stream if a history substitution
is not already in progress. This ! may be preceded by a \
to prevent its special meaning; a ! is passed unchanged when
it is followed by a blank, tab, new-line character, =, or (.
History substitutions also occur when an input line begins
with ^. This special abbreviation will be described later.
Rev. 1.3 Page 3
csh(1) INTERACTIVE UNIX System csh(1)
Any input line that contains a history substitution is
echoed on the terminal before it is executed as it could
have been typed without a history substitution.
Commands input from the terminal that consist of one or more
words are saved on the history list, the size of which is
controlled by the history variable. The previous command is
always retained. Commands are numbered sequentially from 1.
For example, consider the following output from the history
command:
9 write michael
10 ex write.c
11 cat oldwrite.c
12 diff *write.c
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 prompt by placing an !
in the prompt string.
With the current event 13, we can refer to previous events
by event number !11, relatively as in !-2 (referring to the
same event), by a prefix of a command word as in !d for
event 12 or !w for event 9, or by a string contained in a
word in the command as in !?mic? also referring to event 9.
These forms, without further modification, simply re-
introduce the words of the specified events, each separated
by a single blank. As a special case, !! refers to the pre-
vious command; thus, !! alone is essentially a redo. The
form !# references the current command (the one being typed
in). It allows a word to be selected from further left in
the line, to avoid retyping a long name, as in !#:1.
To select words from an event, we can follow the event
specification by a : 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 argu-
ment) being 1, and so on. The basic word designators are as
follows:
Designator Description
0 First (command) word
n nth argument
^ First argument, i.e., 1
$ Last argument
% Word matched by (immediately preceding) ?s?
Rev. 1.3 Page 4
csh(1) INTERACTIVE UNIX System csh(1)
search
x-y Range of words
-y Abbreviates 0-y
* Abbreviates ^-$, or nothing if only one word
in event
x* Abbreviates x-$
x- Like x* but omitting word $
The colon separating the event specification from the word
designator can be omitted if the argument selector begins
with a , $, *, -, or %. After the optional word designator,
a sequence of modifiers can be placed, each preceded by a :.
The following modifiers are defined:
Modifier Description
h Removes a trailing path name component.
r Removes a trailing .xxx component.
s/l/r/ Substitutes l for r.
t Removes all leading path name components.
& Repeats the previous substitution.
g Applies the change globally, prefixing the
above.
p Prints the new command but does not execute
it.
q Quotes the substituted words, preventing sub-
stitutions.
x Like q, but breaks into words at blanks,
tabs, and new-line characters.
Unless preceded by a g, the modification is applied only to
the first modifiable word. In any case, it is an error for
no word to be applicable.
The left side of substitutions are not regular expressions
in the sense of the editors but rather strings. Any charac-
ter may be used as the delimiter in place of a slash (/); a
backslash (\) quotes the delimiter into the l and r strings.
The character & in the right-hand side is replaced by the
text from the left-hand side. A \ quotes & also. A null l
Rev. 1.3 Page 5
csh(1) INTERACTIVE UNIX System csh(1)
uses the previous string either from a l or from a contex-
tual scan string s in !?s?. The trailing delimiter in the
substitution may be omitted if a new-line character follows
immediately, as may the trailing ? in a contextual scan.
A history reference may be given without an event specifica-
tion, e.g., !$. In this case, the reference is to the pre-
vious command unless a previous history reference occurred
on the same line, in which case this form repeats the previ-
ous reference. Thus, !?foo?^!$ gives the first and last
arguments from the command matching ?foo?.
A special abbreviation of a history reference occurs when
the first nonblank character of an input line is a ^. This
is equivalent to !:s^, providing a convenient shorthand for
substitutions on the text of the previous line. Thus,
^lb^lib fixes the spelling of lib in the previous command.
Finally, a history substitution may be surrounded with { and
} if necessary to insulate it from the characters that fol-
low. Thus, after ls -ld ~paul we might do !{l}a to do ls
-ld ~paula, while !la would look for a command starting with
la.
Quotations With Single Quotes (') and Double Quotes (")
The quotation of strings by ' and " can be used to prevent
all or some of the remaining substitutions. Strings
enclosed in ' are prevented from any further interpretation.
Strings enclosed in " are variable, and command expansion
may occur.
In both cases, the resulting text becomes (all or part of) a
single word; only in one special case (see Command Substitu-
tion below) does a " quoted string yield parts of more than
one word; ' quoted strings never do.
Alias Substitution
The shell maintains a list of aliases that can be esta-
blished, displayed, and modified by the alias and 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 has an alias. If it
does, then the text which is the alias for that command 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.
Thus, if the alias for ls is ls -l, the command ls /usr
would map to ls -l /usr. Similarly, if the alias for lookup
was grep !^ /etc/passwd, then lookup bill would map to grep
bill /etc/passwd.
Rev. 1.3 Page 6
csh(1) INTERACTIVE UNIX System csh(1)
If an alias is found, the word transformation of the input
text is performed and the aliasing 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.
Note that the mechanism allows aliases to introduce parser
metasyntax. Thus, you can alias print 'pr \!* | lpr' to
make a command that paginates its arguments to the line
printer.
Variable Substitution
The shell maintains a set of variables, each of which has as
value zero or more words. Some of these variables are set
by the shell or referred to by it. For instance, the argv
variable is an image of the shell's argument list, and words
of this variable's value are referred to in special ways.
The values of variables may be displayed and changed by
using the set and 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 verbose variable is a toggle that causes
command input to be echoed. The setting of this variable
results from the -v command line option.
Other operations treat variables numerically. The at-sign
(@) command permits numeric calculations to be performed and
the result assigned to a variable. However, variable values
are always represented as (zero or more) strings. For the
purposes of numeric operations, the null string is con-
sidered to be zero, and the second and subsequent words of
multiword values are ignored.
After the input line is aliased and parsed, and before each
command is executed, variable substitution is performed,
keyed by dollar sign ($) characters. This expansion can be
prevented by preceding the dollar sign with a backslash (\)
except within double quotation marks ("), in which case it
always occurs, and within single quotation marks (') where
it never occurs. Strings quoted by back quotation marks (`)
are interpreted later (see Command Substitution below) so
dollar sign substitution does not occur there until later,
if at all. A dollar sign is passed unchanged if followed by
a blank, tab, or end-of-line.
Input and output redirections are recognized before variable
expansion and are expanded separately. Otherwise, the com-
mand name and entire argument list are expanded together.
It is thus possible for the first (command) word to generate
more than one word, the first of which becomes the command
name, and the rest of which become arguments.
Rev. 1.3 Page 7
csh(1) INTERACTIVE UNIX System csh(1)
Unless enclosed in double quotation marks or given the :q
modifier, the results of variable substitution may eventu-
ally be command and file name substituted. Within double
quotation marks (") a variable whose value consists of mul-
tiple words expands to a portion of a single word, with the
words of the variable's value separated by blanks. When the
:q 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 file name sub-
stitution.
The following sequences are provided for introducing vari-
able values into the shell input. Except as noted, it is an
error to reference a variable that is not set.
$name
${name}
Are replaced by the words of the value of variable
name, each separated by a blank. Braces insulate name
from following characters which would otherwise be part
of it. Shell variables have names consisting of up to
20 letters, digits, and underscores.
If name is not a shell variable, but is set in the
environment, then that value is returned. However,
modifiers and the other forms shown in the following
list are not available in this case:
$name[selector]
${name[selector]}
May be used to select only some of the words from the
value of name. The selector is subjected to $ substi-
tution and may consist of a single number or two
numbers separated by a -. The first word of a variable
value is numbered 1. If the first number of a range is
omitted, it defaults to 1. If the last member of a
range is omitted, it defaults to $#name. The selector
* selects all words. It is not an error for a range to
be empty if the second argument is omitted or in range.
$#name
${#name}
Gives the number of words in the variable. This is
useful for later use in a [selector].
$0
Substitutes the name of the file from which command
input is being read. An error occurs if the name is
not known.
$number
${number}
Equivalent to $argv[number].
Rev. 1.3 Page 8
csh(1) INTERACTIVE UNIX System csh(1)
$* Equivalent to $argv[*].
The modifiers :h, :t, :r, :q, and :x may be applied to the
substitutions above, as may :gh, :gt, and :gr. If braces
({}) appear in the command form, then the modifiers must
appear within the braces. Only one : modifier is allowed on
each $ expansion.
The following substitutions may not be modified with :
modifiers:
$?name
${?name}
Substitutes the string 1 if name is set and 0 if it is
not.
$?0 Substitutes 1 if the current input file name is known
and 0 if it is not.
$$ Substitutes the (decimal) process number of the
(parent) shell.
Command and File Name Substitution
Command and file name substitution are applied selectively
to the arguments of built-in commands. This means that por-
tions of expressions that are not evaluated are not sub-
jected 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.
Command Substitution
Command substitution is indicated by a command enclosed in
back quotation marks. The output from such a command is
normally broken into separate words at blanks, tabs, and
new-lines, with null words being discarded. This text then
replaces the original string. Within double quotation
marks, only new-line characters force new words; blanks and
tabs are preserved.
In any case, the single final new-line character does not
force a new word. Note that it is thus possible for a com-
mand substitution to yield only part of a word, even if the
command displays a complete line.
File Name Substitution
If a word contains any of the characters *, ?, [, or {, or
begins with the character ~, then that word is a candidate
for file name substitution, also known as ``globbing.''
This word is then regarded as a pattern and is replaced with
an alphabetically sorted list of file names that match the
pattern. In a list of words specifying file name
Rev. 1.3 Page 9
csh(1) INTERACTIVE UNIX System csh(1)
substitution, it is an error for no pattern to match an
existing file name, but it is not required for each pattern
to match. Only the metacharacters *, ?, and [ imply pattern
matching; the characters ~ and { being more akin to abbrevi-
ations.
In matching file names, the character . at the beginning of
a file name or immediately following a /, as well as the
character /, must be matched explicitly. The * character
matches any string of characters, including the null string.
The ? character matches any single character. The sequence
[...] matches any one of the characters enclosed. Within
[...], a pair of characters separated by - matches any char-
acter lexically between the two.
The ~ character at the beginning of a file name is used to
refer to home directories. Standing alone it expands to the
invoker's home directory as reflected in the value of the
variable home. When followed by a name consisting of
letters, digits, and - characters, the shell searches for a
user with that name and substitutes the user's home direc-
tory; thus, ~ken might expand to /usr/ken and ~ken/chmach to
/usr/ken/chmach. If the ~ character is followed by a char-
acter other than a letter or /, or does not appear at the
beginning of a word, it is left unchanged.
The metanotation a{b,c,d}e is a shorthand for abe ace ade.
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,
~source/s1/{oldls,ls}.c expands to /usr/source/s1/oldls.c
/usr/source/s1/ls.c, whether or not these files exist,
without any chance of error if the home directory for source
is /usr/source. Similarly ../{memo,*box} might expand to
../memo ../box ../mbox. (Note that memo was not sorted with
the results of matching *box.) As a special case {, }, and
{} are passed unchanged.
Input/Output
The standard input and standard output of a command may be
redirected with the following syntax:
< name
Opens file name (which is first variable, command, and
file name expanded) as the standard input.
<< word
Reads the shell input up to a line which is identical
to word. word is not subjected to variable, file name,
or command substitution, and each input line is com-
pared to word before any substitutions are made on this
input line. Unless a quoting backslash, double or sin-
gle quotation mark, or a back quotation mark appears in
Rev. 1.3 Page 10
csh(1) INTERACTIVE UNIX System csh(1)
word, variable and command substitution is performed on
the intervening lines, allowing \ to quote $, \, and `.
Commands that are substituted have all blanks, tabs,
and new-line characters preserved except for the final
new-line character, which is dropped. The resulting
text is placed in an anonymous temporary file, which is
given to the command as standard input.
> name
>! name
>& name
>&! name
The file 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.
If the variable noclobber is set, then the file must
not already exist or it must be a character special
file (e.g., a terminal or /dev/null), or an error
results. This helps prevent accidental destruction of
files. In this case, the ! forms can be used to
suppress this check.
The forms involving & route the diagnostic output into
the specified file as well as the standard output.
name is expanded in the same way as < input file names
are.
>> name
>>& name
>>! name
>>&! name
Uses file name as standard output like > but places
output at the end of the file. If the variable
noclobber is set, then it is an error for the file not
to exist unless one of the ! forms is given. Other-
wise, it is similar to >.
If a command is run detached (followed by &), then the
default standard input for the command is the empty file
/dev/null. Otherwise, the 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 pipe-
line. Thus, unlike some previous shells, commands run from
a file of shell commands have no access to the text of the
commands by default; rather they receive the original stan-
dard input of the shell. The << 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.
Diagnostic output may be directed through a pipe with the
standard output. Simply use the form |& rather than just |.
Rev. 1.3 Page 11
csh(1) INTERACTIVE UNIX System csh(1)
Expressions
A number of the built-in commands (to be described later)
take expressions, in which the operators are similar to
those of C, with the same precedence. These expressions
appear in the @, exit, if, and while commands. The follow-
ing operators are available:
|| && | & == != <= >= < > << >> + - * / % ! ~ ( )
Here the precedence increases to the right, with the follow-
ing operators forming groups at the same level:
== and !=
<=, >=, <, and >
<< and >>
+ and -
* / and %
The == and != operators compare their arguments as strings;
all others operate on numbers. Strings that begin with 0
are considered octal numbers. Null or missing arguments are
considered 0. The result of all expressions are strings,
which represent decimal numbers. It is important to note
that no two components of an expression can appear in the
same word; they should be surrounded by spaces except when
adjacent to components of expressions which are syntacti-
cally significant to the parser [& | < > ( )].
Also available in expressions as primitive operands are com-
mand executions enclosed in { and } and file enquiries of
the form -l name, where l is one of the following charac-
ters:
r read access
w write access
x execute access
e existence
o ownership
z zero size
f plain file
d directory
The specified name is command- and file name-expanded, 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., 0. Command execu-
tions succeed, returning true, i.e., 1, if the command exits
with status 0; otherwise, they fail, returning false, i.e.,
0. If more detailed status information is required, then
the command should be executed outside of an expression and
the variable status examined.
Control Flow
Rev. 1.3 Page 12
csh(1) INTERACTIVE UNIX System csh(1)
The shell contains a number of commands that can be used to
control command files (shell scripts) and, in limited but
useful ways, 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.
The foreach, switch, and while statements, as well as the
if-then-else form of the if statement, require that the
major keywords appear in a single command line.
If the shell'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
commands will succeed on nonseekable inputs.)
Built-In Commands
Built-in commands are executed within the shell. If a
built-in command occurs as any component of a pipeline
except the last, then it is executed in a subshell. The
following list describes the syntax and function of the
built-in commands:
alias
alias name
alias name wordlist
The first form prints all aliases. The second form
prints the alias for name. The final form assigns the
specified wordlist as the alias of name; wordlist is
command and file name substituted. name is not allowed
to be alias or unalias.
bg
bg% job... Puts the current or specified jobs into the
background, continuing them if they were stopped.
break
Causes execution to resume after the end of the nearest
enclosing foreach or while statement. The remaining
commands on the current line are executed. Multilevel
breaks are thus possible by writing them all on one
line.
breaksw
Causes a break from a switch, resuming after the endsw.
case label:
A label in a switch statement as discussed below.
cd
cd name
chdir
chdir name
Rev. 1.3 Page 13
csh(1) INTERACTIVE UNIX System csh(1)
Changes the shell's working directory to directory
name. If no argument is given, then it changes to the
home directory of the user. If name is not found as a
subdirectory of the current directory (and does not
begin with /, ./, or ../), then each component of the
variable cdpath is checked to see if it has a subdirec-
tory name. Finally, if all else fails but name is a
shell variable whose value begins with /, then this is
tried to see if it is a directory.
continue
Continues execution of the nearest enclosing while or
foreach. The rest of the commands on the current line
are executed.
default:
Labels the default case in a switch statement. The
default should come after all case labels.
dirs Prints the directory stack; the top of the stack is at
the left, the first directory in the stack being the
current directory.
echo wordlist
The specified words are written to the shell's standard
output. A \c causes the echo to complete without
printing a new-line character. A \n in wordlist causes
a new-line character to be printed. Otherwise, the
words are echoed, separated by spaces.
else
end
endif
endsw
See the following descriptions of the foreach, if,
switch, and while statements.
exec command
The specified command is executed in place of the
current shell.
exit
exit (expr)
The shell exits either with the value of the status
variable (first form) or with the value of the speci-
fied expr (second form).
foreach name (wordlist)
...
end
The variable name is successively set to each member of
wordlist, and the sequence of commands between this
command and the matching end are executed. (Both
Rev. 1.3 Page 14
csh(1) INTERACTIVE UNIX System csh(1)
foreach and end must appear alone on separate lines.)
The built-in command continue may be used to continue
the loop prematurely, and the built-in command break
may be used to terminate it prematurely. When this
command is read from the terminal, the loop is read up
once prompting with ? before any statements in the loop
are executed.
glob wordlist
Like echo, but no \ escapes are recognized, and words
are delimited by null characters in the output. Useful
for programs that wish to use the shell to file name-
expand a list of words.
goto word
The specified word is file name-and-command expanded to
yield a string of the form label. The shell rewinds
its input as much as possible and searches for a line
of the form label: possibly preceded by blanks or
tabs. Execution continues after the specified line.
history
Displays the history event list.
if (expr) command
If the specified expression evaluates true, then the
single command with arguments is executed. Variable
substitution on command happens early, at the same time
it does for the rest of the if command. Command must
be a simple command, not a pipeline, a command list, or
a parenthesized command list. Input/output redirection
occurs even if expr is false, when command is not exe-
cuted.
if (expr) then
...
else if (expr2) then
...
else
...
endif
If the specified expr is true, then the commands to the
first else are executed; else if expr2 is true, then
the commands to the second else are executed, etc. Any
number of else-if pairs are possible; only one endif is
needed. The else part is likewise optional. (The
words else and endif must appear at the beginning of
input lines; the if must appear alone on its input line
or after an else.)
jobs
jobs -l
Rev. 1.3 Page 15
csh(1) INTERACTIVE UNIX System csh(1)
Lists the active jobs; given the -l options lists pro-
cess IDs in addition to the normal information.
kill %job
kill -sig %job
kill pid
kill -sig pid ...
kill -l
Sends either the TERM (terminate) signal or the speci-
fied signal to the specified jobs or processes. Sig-
nals are either given by number or by names (as given
in /usr/inlude/signal.h, stripped of the prefix
``SIG''). The signal names are listed by ``kill -l.''
There is no default; saying only ``kill'' 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.
limit
limit resource
limit resource maximum-use
limit -h
limit -h resource
limit -h resource maximum-use
Limits the consumption by the current process and each
process it creates to not individually exceed maximum-
use on the specified resource. If no maximum-use is
given, then the current limit is printed; if no
resource is given, then all limitations are given. If
the -h flag is given, the hard limits are used instead
of the current limits. The hard limits impose a ceil-
ing on the values of the current limits. Only the
superuser may raise the hard limits, but a user may
lower or raise the current limits within the legal
range.
Resources controllable currently include cputime (the max-
imum number of cpu-seconds to be used by each process),
filesize (the largest single file which can be created),
datasize (the maximum growth of the data+stack region via
sbrk(2) beyond the end of the program text), stacksize (the
maximum size of the automatically-extended stack region),
and coredumpsize (the size of the largest core dump that
will be created).
The maximum-size may be given as a (floating point or
integer) number followed by a scale factor. For all limits
other than cputime the default scale is ``k'' or ``kilo-
bytes'' (1024 bytes); a scale factor of ``m'' or ``mega-
bytes'' may also be used. For cputime the default scaling
is ``seconds,'' while ``m'' for minutes or ``h'' for hours,
or a time of the form ``mm:ss'' giving minutes and seconds
may be used.
For both resource names and scale factors, unambiguous
Rev. 1.3 Page 16
csh(1) INTERACTIVE UNIX System csh(1)
prefixes of the names suffice.
logout
Terminates a login shell. The only way to log out if
ignoreeof is set.
nice
nice +number
nice command
nice +number command
The first form sets the nice for this shell to 4. The
second form sets the nice to the given number. The
final two forms run command at priority 4 and number
respectively. The superuser may specify negative nice-
ness by using ``nice -number ....'' The command is
always executed in a subshell, and the restrictions
placed on commands in simple if statements apply.
nohup
nohup command
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. Unless the shell is running
detached, nohup has no effect. All processes detached
with & are automatically run with nohup. (Thus nohup
is not really needed.)
notify
notify%job ...
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 notify is set.
onintr
onintr -
onintr label
Controls the action of the shell on interrupts. The
first form restores the default action of the shell on
interrupts: to terminate shell scripts or to return to
the terminal command input level. The second form
onintr - causes all interrupts to be ignored. The
final form causes the shell to execute a goto label
when an interrupt is received or a child process ter-
minates because it was interrupted.
In any case, if the shell is running detached and
interrupts are being ignored, all forms of onintr have
no meaning, and interrupts continue to be ignored by
the shell and all invoked commands.
rehash
Causes the internal hash table of the directories'
Rev. 1.3 Page 17
csh(1) INTERACTIVE UNIX System csh(1)
contents in the path variable to be recomputed. This
is needed if new commands are added to directories in
the path while you are logged in. This should be
necessary only if you add commands to one of your own
directories or if a systems programmer changes the con-
tents of one of the system directories.
repeat count command
The specified command, which is subject to the same
restrictions as the command in the one line if state-
ment above, is executed count times. I/O redirections
occur exactly once, even if count is 0.
set
set name
set name=word
set name[index]=word
set name=(wordlist)
The first form of the command shows the value of all
shell variables. Variables that have other than a sin-
gle word as value print as a parenthesized word list.
The second form sets name to the null string. The
third form sets name to the single word. The fourth
form sets the index component of name to word; this
component must already exist. The final form sets name
to the list of words in wordlist. In all cases the
value is command- and file name-expanded. These argu-
ments may be repeated to set multiple values in a sin-
gle set command. Note, however, that variable expan-
sion happens for all arguments before any setting
occurs.
setenv name value
Sets the value of the environment variable name to be
value, a single string. Useful environment variables
are TERM, the type of your terminal, and SHELL, the
shell you are using.
shift
shift variable
The members of argv are shifted to the left, discarding
argv[1]. It is an error for argv not to be set or to
have less than one word as value. The second form per-
forms the same function on the specified variable.
source name
The shell reads commands from name. source commands
may be nested; if they are nested too deeply, the shell
may run out of file descriptors. An error in a source
at any level terminates all nested source commands.
Input during source commands is never placed on the
history list.
stop
Rev. 1.3 Page 18
csh(1) INTERACTIVE UNIX System csh(1)
stop%job ...
Stops the current or specified job which is executing
in the background.
suspend
Causes the shell to stop in its tracks, much as if it
had been sent a stop signal with ^Z. This is most
often used to stop shells started by su(1).
switch (string)
case str1:
...
breaksw
...
default:
...
breaksw
endsw
Each case label is successively matched against the
specified string that is first command- and file name-
expanded. The file metacharacters *, ?, and [...] may
be used in the case labels, which are variable-
expanded. If none of the labels match before a default
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
breaksw causes execution to continue after the 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 endsw.
time
time command
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 sum-
mary as described under the time variable is printed.
If necessary, an extra shell is created to print the
time statistic when the command completes.
umask
umask value
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 all access except no
write access for users in the group or others.
unalias pattern
All aliases whose names match the specified pattern are
discarded. Thus, all aliases are removed by unalias *.
It is not an error for nothing to match the unalias
Rev. 1.3 Page 19
csh(1) INTERACTIVE UNIX System csh(1)
pattern.
unhash
Use of the internal hash table to speed location of
executed programs is disabled.
unlimit
unlimit resource
unlimit -h
unlimit -h resource
Removes the limitation on resource. If no resource is
specified, then all resource limitations are removed.
If -h is given, the corresponding hard limits are
removed. Only the superuser may do this.
unset pattern
All variables whose names match the specified pattern
are removed. Thus, all variables are removed by unset
*; this has noticeably undesirable side-effects. It is
not an error for nothing to be unset.
wait
All child processes are waited for. It the shell is
interactive, then an interrupt can disrupt the wait, at
which time the shell prints names and process numbers
of all children known to be outstanding.
while(expr)
...
end
While the specified expression evaluates nonzero, the
commands between the while and the matching end are
evaluated. Break and continue may be used to terminate
or continue the loop prematurely. (The while and end
must appear alone on their input lines.) Prompting
occurs here the first time through the loop as for the
foreach statement if the input is a terminal.
%job Brings the specified job into the foreground.
%job &
Continues the specified job in the background.
@
@ name = expr
@ name [ index ] = expr
The first form prints the values of all the shell vari-
ables. The second form sets the specified name to the
value of expr. If the expression contains <, >, &, or
|, then at least this part of the expression must be
placed within ( The third form assigns the value of
expr to the index argument of name. Both name and its
index component must already exist.
Rev. 1.3 Page 20
csh(1) INTERACTIVE UNIX System csh(1)
Assignment operators, such as *= and +=, are available
as in C. The space separating the name from the
assignment operator is optional. Spaces are mandatory
in separating components of expr which would otherwise
be single words.
Special postfix ++ and - - operators increment and
decrement name respectively, i.e., @ i++.
Predefined Variables
The following variables have special meaning to the shell.
Of these, argv, child, home, path, prompt, shell, and status
are always set by the shell. Except for child and status,
this setting occurs only at initialization; these variables
will not then be modified unless done explicitly by the
user.
Variable Description
argv Set to the arguments of the shell; from this
variable, positional parameters are substi-
tuted, i.e., $1 is replaced by $argv[1].
cdpath Gives a list of alternate directories
searched to find subdirectories in cd com-
mands.
child The process number printed when the last com-
mand was forked with &. This variable is
unset when this process terminates.
echo Set when the -x command line option is given.
Causes each command and its arguments to be
echoed just before it is executed. For
nonbuilt-in commands, all expansions occur
before echoing. Built-in commands are echoed
before command and file name substitution
since these substitutions are then done
selectively.
histchars Can be assigned a two-character string. The
first character is used as a history charac-
ter in place of !; the second character is
used in place of the ^ substitution mechan-
ism. For example, set histchars = ,; will
cause the history characters to be comma and
semicolon.
history Can be given a numeric value to control the
size of the history list. Any command that
has been referenced in this many events will
not be discarded. A history that is too
large may run the shell out of memory. The
Rev. 1.3 Page 21
csh(1) INTERACTIVE UNIX System csh(1)
last executed command is always saved on the
history list.
home The home directory of the user, initialized
from the environment. The file name expan-
sion of ~ refers to this variable.
ignoreeof If set, the shell ignores the end-of-file
from input devices that are terminals. This
prevents a shell from accidentally being ter-
minated by typing a CTRL-D.
mail The files where the shell checks for mail.
This is done after each command completion
results in a prompt, if a specified interval
has elapsed. The shell sends the message
``You have new mail'' if the file exists with
an access time not greater than its modify
time. If the first word of the value of mail
is numeric, it specifies a different mail
checking interval, in seconds, than the
default, which is 10 minutes. If multiple
mail files are specified, then the shell
sends the message ``New mail in name'' when
there is mail in the file name.
noclobber Restrictions are placed on output redirection
to insure that files are not accidentally
destroyed and that >> redirections refer to
existing files.
noglob If set, file name expansion is inhibited.
This is most useful in shell scripts that are
not dealing with file names or after a list
of file names has been obtained and further
expansions are not desirable.
nonomatch If set, it is not an error for a file name
expansion to not match any existing files;
rather, the primitive pattern is returned.
It is still an error for the primitive pat-
tern to be malformed, i.e., echo [ still
gives an error.
notify If set, the shell notifies asynchronously of
job completions. The default is to rather
present job completions just before printing
a prompt.
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 path
Rev. 1.3 Page 22
csh(1) INTERACTIVE UNIX System csh(1)
variable, then only full path names will exe-
cute. The usual search path is /bin,
/usr/bin, and ., but this may vary from sys-
tem to system. For the superuser, the
default search path is /etc, /bin and
/usr/bin. A shell that is given neither the
-c nor the -t option will normally hash the
contents of the directories in the path vari-
able after reading .cshrc and each time the
path variable is reset. If new commands are
added to these directories while the shell is
active, it may be necessary to give the
rehash, or the commands may not be found.
prompt The string that is printed before each com-
mand is read from an interactive terminal
input. If a ! appears in the string, it will
be replaced by the current event number
unless a preceding \ is given. The default
is % or # for the superuser.
shell The file in which the shell resides. This is
used in forking shells to interpret files
that have execute bits set but are not exe-
cutable by the system (see the section
Nonbuilt-In Command Execution below.) shell
is initialized to the system-dependent home
of the shell.
status The status returned by the last command. If
it terminated abnormally, then 0200 is added
to the status. Abnormal termination results
in a core dump. Built-in commands that fail
return exit status 1; all other built-in com-
mands set status 0.
time Controls automatic timing of commands. If
set, then any command that takes more than
this many CPU seconds will cause a line giv-
ing user, system, and real times and a utili-
zation percentage (ratio of user plus system
times to real time) to be printed when it
terminates.
verbose Set by the -v command line option, causes the
words of each command to be printed after
history substitution.
The shell copies the environment variable PATH into the
variable path and copies the value back into the environment
whenever path is set. Thus, it is not necessary to worry
about its setting other than in the file .cshrc as inferior
csh processes will import the definition of path from the
Rev. 1.3 Page 23
csh(1) INTERACTIVE UNIX System csh(1)
environment.
Nonbuilt-In Command Execution
When a command to be executed is found to not be a built-in
command, the shell attempts to execute the command via
exec(2). Each word in the variable path names a directory
from which the shell will attempt to execute the command.
If it is given neither a -c nor a -t option, the shell will
hash the names in these directories into an internal table
so that it will only try an 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 unhash) or if the shell was given a -c or -t
argument, and in any case for each directory component of
path which does not begin with a /, the shell concatenates
with the given command name to form a path name of a file
which it then attempts to execute.
Parenthesized commands are always executed in a subshell.
Thus (cd ; pwd) ; pwd prints the home directory, leaving you
where you were (printing this after the home directory),
while cd ; pwd leaves you in the home directory.
Parenthesized commands are most often used to prevent cd
from affecting the current shell.
If the file has execute permissions but is not an executable
binary to the system, then it is assumed to be a file con-
taining shell commands and a new shell is spawned to read
it.
If there is an alias for shell, then the words of the alias
will be prepended to the argument list to form the shell
command. The first word of the alias should be the full
path name of the shell (e.g., $shell). Note that this is a
special, late occurring case of alias substitution and only
allows words to be prepended to the argument list without
modification.
Argument List Processing
If argument 0 to the shell is -, then this is a login shell.
The flag arguments are interpreted as follows:
Flag Description
-c Reads commands from the (single) following argument
which must be present. Any remaining arguments are
placed in argv.
-e Causes the shell to exit if any invoked command ter-
minates abnormally or yields a nonzero exit status.
-f Lets the shell start faster because it will neither
Rev. 1.3 Page 24
csh(1) INTERACTIVE UNIX System csh(1)
search for nor execute commands from the file .cshrc
in the user's home directory.
-i Makes the shell interactive. The shell prompts for
its top-level input even if it appears not to be a
terminal. Shells are interactive without this
option if their inputs and outputs are terminals.
-n Causes commands to be parsed but not executed. This
may aid in syntactic checking of shell scripts.
-s Causes command input to be taken from the standard
input.
-t Reads and executes a single line of input. A
backslash (\) can be used to escape the new-line
character at the end of this line and continue onto
another line.
-v Causes the verbose variable to be set, with the
effect that command input is echoed after history
substitution.
-x Causes the echo variable to be set so that commands
are echoed immediately before execution.
-V Causes the verbose variable to be set even before
.cshrc is executed.
-X Causes the echo variable to be set even before
.cshrc is executed.
After processing of flag arguments, if arguments remain but
none of the -c, -i, -s, or -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 $0. Since on a typical system
most shell scripts are written for the standard shell (see
sh(1)), the C shell will execute such a standard shell if
the first character of a script is not a #, i.e., if the
script does not start with a comment. Remaining arguments
initialize the variable argv.
Signal Handling
The shell normally ignores quit signals. The interrupt and
quit signals are ignored for an invoked command if the com-
mand is followed by &; otherwise, the signals have the
values that the shell inherited from its parent. The
shell's handling of interrupts can be controlled by onintr.
Login shells catch the terminate signal; otherwise, this
signal is passed on to children from the state in the
shell's parent. In no case are interrupts allowed when a
login shell is reading the file .logout.
Rev. 1.3 Page 25
csh(1) INTERACTIVE UNIX System csh(1)
NEW ENVIRONMENT VARIABLES
The new environment variable described in this section has
been added to the C shell. The C shell will behave normally
for those users who do not set DOSPATH. Users who wish to
be able to execute MS-DOS (DOS) programs directly from the C
shell, that is, bypassing the normal DOS bootup that occurs
when running vpix, should set DOSPATH to include those
directories in PATH that contain DOS executables.
DOSPATH is a string with the same format as PATH; it con-
tains a subset of the list of directories from PATH. When
searching a directory in PATH for a program, the C shell
determines whether that directory is also in DOSPATH. If it
is not, the C shell acts as usual. If it is, the C shell
looks first for the command with the suffix .com, then .exe,
then .bat, and finally, for the command without any suffix.
Whenever the result of a path search gives a file with one
of these DOS suffixes, the shell runs the vpix program via a
standard search path and adds arguments -c and the full path
name of the DOS program (including the suffix).
For example, if PATH is set to :/bin:/usr/bin, DOSPATH is
set to ., the current directory is /usr/john/dosbin, and
there is a DOS program named abc.comi in the current direc-
tory, then typing abc to the C shell will cause the command
vpix -c /usr/john/dosbin/abc.com to be executed, which will
run the DOS program abc.com without the normal vpix DOS
bootup.
FILES
~/.cshrc Read by each shell at the beginning of execu-
tion
~/.login Read by login shell after .cshrc at login
~/.logout Read by login shell at logout
/bin/sh Shell for scripts not starting with a #!
/bin/csh
/tmp/sh* Temporary file for <<
/dev/null Source of empty file
/etc/passwd Source of home directories for ~name
/etc/default/.cshrc
Default file of automatically invoked com-
mands
SEE ALSO
umask(1), wait(1).
access(2), exec(2), fork(2), pipe(2), signal(2), a.out(4),
environ(5) in the INTERACTIVE SDS Guide and Programmer's
Reference Manual.
CREDIT
This utility was developed at the University of California
at Berkeley and is used with permission.
Rev. 1.3 Page 26
csh(1) INTERACTIVE UNIX System csh(1)
NOTES
Words can be no longer than 512 characters. The number of
arguments to a command which involves file name expansion is
limited to 1/6 of the number of characters allowed in an
argument list, which is 5120 less the characters in the
environment. Also, command substitutions may substitute no
more characters than are allowed in an argument list.
To detect looping, the shell restricts the number of alias
substitutions on a single line to 20.
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.
Built-in control structure commands like foreach and while
cannot be used with the pipe symbol (|), ampersand (&), or
semicolon (;).
Shell built-in functions are not stoppable/restartable.
Command sequences of the form ``a;b;c'' are also not handled
gracefully when stopping is attempted. If you suspend
``b,'' the shell will then immediately execute ``c.'' This
is especially noticeable if this expansion results from an
alias. It suffices to place the sequence of commands in
parentheses to force it to a subshell; i.e., ``(a;b;c).''
Commands within loops prompted for by ? are not placed in
the history list.
It is not possible to use the colon (:) modifiers on the
output of command substitutions.
csh attempts to import and export the PATH variable for use
with regular shell scripts. This only works for simple
cases, where the PATH contains no command characters.
This version of csh does not support or use the process con-
trol features of the 4th Berkeley Distribution.
You can modify the list of commands that csh automatically
invokes by editing the /etc/default/.cshrc file. For exam-
ple, if you want to automatically assign the alias h to the
history command, add the following line to the
/etc/default/.cshrc file using the computer editor of your
choice:
alias history h
Rev. 1.3 Page 27