CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
NAME
csh - a shell (command interpreter) with C-like syntax
SYNOPSIS
csh [ -cefinstvVxX ] [ arg ... ]
DESCRIPTION
csh is a command language interpreter incorporating a his-
tory mechanism (see History substitutions) and a C-like syn-
tax.
An instance of csh begins by executing commands from the
file .cshrc in the home directory of the invoker. If this
is a login shell, then it also executes commands from the
file .login there. It is typical for users on CRTs to
invoke tset(1) there.
In the normal case, the shell will then begin reading com-
mands from the terminal, prompting with %. Processing of
arguments and the use of the shell to process files contain-
ing 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 &, |, ;, <,
>, (, ), form separate words. If doubled in &&, ||, << or
>>, these pairs form single words. These parser metacharac-
ters may be made part of other words, or their special mean-
ing may be prevented, by preceding them with a backslash
(\). A newline preceded by a \ is equivalent to a blank.
It is usually necessary to use the backslash to escape the
parser metacharacters when you want to use them literally
rather than as metacharacters.
Strings enclosed in matched pairs of quotation marks, either
single or double quotation marks, form parts of a word.
Metacharacters in these strings, including blanks and tabs,
do not form separate words. Such quotations have semantics
to be described subsequently.
Within pairs of single or double quotation marks, a newline
(carriage return) preceded by a \ gives a true newline char-
acter. This is used to set up a file of strings separated
Printed 1/15/91 Page 1
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
by newlines, as for fgrep.
When the shell's input is not a terminal, the character #
introduces a comment which continues to the end of the input
line. It is prevented from having this special meaning when
preceded by \ or if bracketed by a pair of single or double
quotation marks.
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 a pipeline. The output of each com-
mand in a pipeline is connected to the input of the next.
Sequences of pipelines may be separated by ;, and are then
executed sequentially. A sequence of pipelines may be exe-
cuted without immediately waiting for it to terminate by
following it with an &, which means to run it in background.
Parentheses ( and ) around a pipeline or sequence of pipe-
lines cause the whole series to be treated as a simple com-
mand, which may in turn 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. For example:
# jobs [1] - Running xload [2] + Stopped
mail [3] + Suspended rlogin sprint #
When a process is run in background with &, the shell prints
a line which looks like:
[1] 1234
This line indicates that the job which was started asynchro-
nously was job number 1 and had one (top-level) process,
whose process id was 1234.
If you are running a job and wish to do something else you
may hit the key ^Z or ~^Z (control-Z or tilde-control-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 background with the bg
Page 2 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
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 dis-
carded when it is typed. There is another special 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 which 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 tty
option, then background jobs will stop when they try to pro-
duce output like 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 `%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
abbreviation `%+' refers to the current job and `%-' refers
to the previous job. For close analogy with the syntax of
the history mechanism (described below), `%%' is also a
synonym for the current job.
If you attempt to log out while there are jobs running in
the background, you will get an error message such as
There are stopped jobs.
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.
To check on the status of a process, use the ps (process
status) command.
Printed 1/15/91 Page 3
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
Command Line Editing
The line editor permits a large number of operations beyond
the scope of the current tty driver -- most of the simple
editing commands available in the EMACS screen editor (not
available in 4.3) may be used to move around on and change
the current line. In addition, line editing allows interac-
tive expansion of csh history items. Typing "!foo" followed
by a space, for example, will insert the previous command
starting with "foo" into the line at the current location.
The line editing feature, which is off by default, may be
enabled by setting the shell variable ``lineedit''. (The
variable "lineedit" takes precedence over the variable
"filec" and consequently disables file name completion,
though file name completion is still available under the
line editor by using M-ESC, which by default means typing
two escape characters.) The variable "lineeditmin" speci-
fies the minimum size of history list commands that will be
seen by the line editor. The variable "lineeditchars" gives
a character map which allows the default assignment of the
keys to be changed. In order to use the history mechanism,
you must also set the variable ``history'' to be the number
of previous lines you want remembered.
With ``lineedit'' set to the empty string, the line editor
works on any CRT terminal which meets the following require-
ments:
(1) ASCII linefeed moves the cursor downward
(2) ASCII backspace moves the cursor one column to the
left without erasing the character in that column
(3) ASCII carriage return moves the cursor to the left
margin
(4) ASCII bell character rings the bell
(5) ASCII space character replaces the character in
the current column with a blank space and moves
the cursor one column to the right. By setting
``lineedit'' to a string beginning with a delim-
iter and containing character sequences separated
by that delimiter, you can customize the line edi-
tor for terminals which do not meet these require-
ments. For example, ``set
lineedit="/^j/^h/^m/^g/ /"'' (where you may use
the prefix '^' to indicate a control character) is
equivalent to the default.
The special characters you set using the stty(1) com-
mand are still in effect between commands. If, for
Page 4 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
example, you set your Unix QUIT character to be DEL,
you can use DEL to get yourself out of a program like
mail(1), or to interrupt a program like vi , or even to
break out of a shell ``while'' loop. But while you are
actually editing a line, DEL has a special meaning
described below.
The infallible way to get out of editing is to type
^C^D. Immediately after the prompt, ^D by itself is
sufficient.
The line editor maintains a repetition factor which is
initially 1. This factor is multiplied by 4 by the ^U
command. In the following description, (R) indicates
that the command pays attention to the repetition fac-
tor. The repetition factor returns to 1 after each
command or error, even if the command does not pay
attention to the repetition factor.
^@ Mark line (this lets you browse through the remem-
bered lines with ^P and ^N, mark one, and later
use the marked line with M-Y).
^A Move cursor to beginning of line.
^B Move cursor backward (R).
^C Clear the entire line and reprompt.
^D Delete character above cursor. (If you type ^D
immediately after the prompt, before you type any-
thing else, it has its usual meaning: quit running
the shell). (R)
^E Move cursor to end of line.
^F Move cursor forward (R).
^G Abort the current command and ring the bell.
^H Delete character preceding cursor (R).
^J Activate the line.
^K<char>
Delete characters until cursor is under <char>. If
<char> is ^K, use the same char as the previous
^R, ^S, or ^K command. To delete until ^K, say
``^K^Q^K''. To delete until end of line, say
``^K^M''.
^L Redisplay line on a clean line.
Printed 1/15/91 Page 5
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
^M Activate the line.
^N Go forward one line in the queue of previously-
typed lines and make that be the ``line under con-
struction''. Only lines greater in size than the
shell variable "lineeditmin" are considered. (R)
^P Go backward one line in the queue of previously-
typed lines and make that be the ``line under con-
struction''. Only lines greater in size than the
shell variable "lineeditmin" are considered. (R)
^Q<char>
Insert <char> before the cursor (useful for quot-
ing characters which the line editor itself would
otherwise recognize).
^R<char>
Search backward for <char>. If <char> is ^R, then
it searches instead for the same character as the
previous ^K, ^R or ^S command. To search for ^R,
type ``^R^Q^R''. (R)
^S<char>
Search forward for <char>. If <char> is ^S, then
it searches instead for the same character as the
previous ^K, ^R or ^S command. To search for ^S,
type ``^S^Q^S''. (R)
^T Interchange the two characters preceding the cur-
sor.
^U Multiply the repetition count by 4. Does not take
a numeric argument.
^W Delete the entire line.
^Y (Yank) Insert in front of the cursor the previous
text deleted with ^K, M-D, M-H, or M-DEL.
RUBOUT
Delete character preceding cursor. (R)
Other control characters are illegal, and most send a
bell character to your terminal to try to make it beep.
There are also a few meta-commands, which you can
invoke by typing ASCII ``escape'' before the letter.
M-A Go to the beginning (bottom or most recent) of
the history list.
Page 6 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
M-B Move backward by one word. (R)
M-D Delete next word. (R)
M-E Go to the end (top or earliest) of the history
list.
M-F Move forward by one word. (R)
M-H Delete previous word. (R)
M-U Undo the last non-trivial change.
M-Y (Yank) Insert in front of the cursor the line
marked with ^@.
M-DEL Delete previous word. (R)
M-ESC Complete listings with "ls" style output. Same
as entering Control-D and ESC in file completion
mode.
All ordinary (non-control, non-meta) characters insert
themselves before the cursor. Thus to add characters to
a line, simply type them.
If you set the shell variable ``lineeditmin'' to a
positive integer, the line editor will no longer con-
sider lines shorter than that number of characters in
length. Thus you can prevent ^N and ^P from showing
you trivial lines like vi or ``popd''.
The interactive history expansion mechanism is invoked
by typing a space or a tab after a word containing the
current history character (which defaults to ``!'').
Any history expansion involving just full commands and
arguments thereof (no editing) will be done interac-
tively. In addition to csh's normal ``!foo:i-j''
(where ``i'' and ``j'' are numbers and either may be
elided), the line editor also allows either of ``i'' or
``j'' to be referenced from the end of the argument
list, as in ``!foo:$-2-$'' which yields the last three
arguments of the previous command starting with
``foo''.
The variable "lineeditchars" may be set to change the
default functions for each key, but use great care in
doing so! The default value of this variable is:
``^@^a^b^c^d^e^f^g^h^i^j^k^l^m^n^o^p^q^r^s^t^u^v^w^x^y^z^[^\^]^^^_^?''.
In this string, control characters are specified by
preceding them with an uparrow (``^''), and meta char-
acters are specified by prefixing them with a dollar
Printed 1/15/91 Page 7
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
sign (``$''). In addition, the delete character may be
specified as ``^?''. Each position in this string
corresponds to one of the control characters -- thus
position 0 corresponds to the function for ^@, position
1 to the value for ^A, etc. In addition to the 32 con-
trol positions, position 33 controls the function of
DEL. The value in a position is the default function
binding to be used for that character. Thus, to change
the bindings so that ^W does a word delete (M-H), ^X is
the line kill character (^W), and DEL is the interrupt
character (^C), set lineeditchars to:
``^@^a^b^c^d^e^f^g^h^i^j^k^l^m^n^o^p^q^r^s^t^u^v$h^w^y^z^[^\^]^^^_^c''.
Substitutions
We now describe the various transformations the shell per-
forms on the input in the order in which they occur.
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 ^ and may
begin anywhere in the input stream (with the proviso that
they do not nest.)
This ! may be preceded by a \ to turn off its special mean-
ing; for convenience, a ! is also passed unchanged when it
is followed by a blank, tab, newline, = or (.
Therefore, do not put a space after the ! and the command
reference when you are invoking the shell's history mechan-
ism. (History substitutions also occur when an input line
begins with ^. This special abbreviation will be described
later.)
An input line which invokes history substitution is echoed
on the terminal before it is executed, as it would look if
typed out in full.
The shell's history list, which may be seen by typing the
history command, contains all commands input from the termi-
nal which consist of one or more words. History substitu-
tions reintroduce sequences of words from these saved com-
mands into the input stream. The history variable controls
the size of the input stream. The previous command is
always retained, regardless of its value. Commands are num-
bered sequentially from 1.
Page 8 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
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. This is done by setting prompt = !
and the prompt character of your choice.
For example, if the current event is number 13, we can call
up the command recorded as event 11 in several ways: !-2
[i.e., 13-2]; by the first letter of one of its command
words, such as !c referring to the c in cat; or !wri 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 reintro-
duce the words of the specified events, each separated by a
single blank. As a special case !! refers to the previous
command; thus !! alone is essentially a redo.
Words are selected from a command event and acted upon
according to the following formula:
event:position:action
The event is the command you wish to retrieve. As mentioned
above, it may be summoned up by event number and in several
other ways. All that the event notation does is to tell the
shell which command you have in mind.
position picks out the words from the command event on which
you want the action to take place. The position notation
can do anything from altering the command completely to mak-
ing some very minor substitution, depending on which words
from the command event you specify with the position nota-
tion.
To select words from a command event, follow the event
specification with a : and a designator (by position) for
the desired words.
The words of a command event are picked out by their posi-
tion in the input line. positions are numbered from 0, the
first word (usually command) being position 0, the second
word having position 1, and so forth. If you designate a
word from the command event by stating its position, means
you want to include it in your revised command. All the
Printed 1/15/91 Page 9
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
words that you want to include in a revised command must be
designated by position notation in order to be included.
The basic position designators are:
0 first (command) word
n nth argument
^ first argument, i.e., 1
$ last argument
% matches the word of an ?s? search which immediately
precedes it; used to strip one word out of a command
event for use in another command. Example:
!?four?:%:p prints four.
x-y range of words (e.g., 1-3 means from position 1 to
position 3).
-y abbreviates 0-y
* stands for ^-$, or indicates position 1 if only one
word in event.
x* abbreviates x-$ where
x is a position number.
x- like x* but omitting last word $
The : separating the event specification from the word
designator can be omitted if the argument selector begins
with a ^, $, *, - or %.
Modifiers, each preceded by a :, may be used to act on the
designated words in the specified command event. The fol-
lowing modifiers are defined:
h Remove a trailing pathname component, leaving
the head.
r Remove a trailing .xxx component, leaving the
root name.
e Remove all but the extension .xxx part.
s/old/new/ Substitute new for old
t Remove all leading pathname components, leav-
ing the tail.
& Repeat the previous substitution.
g Apply the change globally, prefixing the
above, e.g., g&.
p Print the new command but do not execute it.
q Quote the substituted words, preventing
further substitutions.
x Like q, but break into words at blanks, tabs
and newlines.
Unless preceded by a g, the modification is applied only to
the first modifiable word. With substitutions it is an
error for no word to be applicable.
Page 10 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
The left hand side of substitutions are not regular expres-
sions in the sense of the editors, but rather strings. Any
character may be used as the delimiter in place of /; a \
quotes the delimiter into the l and r strings. The charac-
ter & in the right hand side is replaced by the text from
the left. A \ quotes & also. A null l uses the previous
string either from a l or from a contextual scan string s in
!?s?. The trailing delimiter in the substitution may be
omitted if (but only if) a newline 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 previ-
ous command. If a previous history reference occurred on
the same line, this form repeats the previous reference.
Thus !?foo?^ !$ gives the first and last arguments from the
command matching ?foo?.
You can quickly make substitutions to the previous command
line by using the ^ character as the first non-blank charac-
ter of an input line. 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 which follow. Thus, after ls -ld ~paul we
might do !{l}a to do ls -ld ~paula, while !la would look for
a command starting la.
Quotations with ' and "
The quotation of strings by ' and " can be used to prevent
all or some of the remaining substitutions which would oth-
erwise take place if these characters were interpreted as
metacharacters or wild card matching characters. Strings
enclosed in single quotes, ' are prevented any further
interpretation or expansion. Strings enclosed in " may
still be variable and command expanded as described below.
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;
Alias substitution
The shell maintains a list of aliases which 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
Printed 1/15/91 Page 11
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
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 , the argument list here being undis-
turbed. Similarly if the alias for lookup was grep !^
/etc/passwd, then lookup bill would map to grep bill
/etc/passwd.
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 we can alias print 'pr \!* | lpr' to make
a command which prs its arguments to the line printer.
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 argv variable is an image of the shell's argument list,
and words of this variable's value are referred to in spe-
cial 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 which causes
command input to be echoed. The setting of this variable
results from the -v command line option.
Other operations treat variables numerically. The @ 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 pur-
poses of numeric operations, the null string is considered
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 $ characters. This expansion can be prevented by
preceding the $ with a \ except within double quotes (")
Page 12 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
where it always occurs, and within single quotes (') where
it never occurs. Strings quoted by ' are interpreted later
(see Command substitution below) so $ substitution does not
occur there until later, if at all. A $ is passed unchanged
if followed by a blank, tab, or end-of-line.
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.
Unless enclosed in double quotes or given the :q modifier,
the results of variable substitution may eventually be com-
mand and filename substituted. Within double quotes, 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 :q modifier is applied
to a substitution, the variable will expand to multiple
words with each word separated by a blank and quoted to
prevent later command or filename substitution.
Metasequences for variable substitution
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.
$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
and digits starting with a letter. The underscore char-
acter is considered a letter.
If name is not a shell variable, but is set in the
environment, then that value is returned (but : modifiers
and the other forms given below 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 $ substitu-
tion and may consist of a single number or two numbers
separated by a -. The first word of a variables 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
Printed 1/15/91 Page 13
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
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 use-
ful 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].
$*
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. The current implementation allows only
one : modifier on each $ expansion.
The following substitutions may not be modified with :
modifiers.
$?name
${?name}
Substitutes the string 1 if name is set, 0 if it is not.
$?0
Substitutes 1 if the current input filename is known, 0
if it is not.
$$
Substitute the (decimal) process number of the (parent)
shell.
$<
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.
Command and filename substitution
The remaining substitutions, command and filename substitu-
tion, are applied selectively to the arguments of built-in
commands. This means that portions of expressions which are
not evaluated are not subjected to these expansions. For
Page 14 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
commands which 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 per-
formed, and in a child of the main shell.
Command substitution
Command substitution is indicated by a command enclosed in
`. 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 replacing the original
string. Within double quotes ("), only newlines force new
words; blanks and tabs are preserved.
In any case, the single final newline does not force a new
word. Note that it is thus possible for a command substitu-
tion to yield only part of a word, even if the command out-
puts a complete line.
Filename substitution
If a word contains any of the characters *, ?, [ or { or
begins with the character ~, then that word is a candidate
for filename substitution, also known as ``globbing''. This
word is then regarded as a pattern, and replaced with an
alphabetically sorted list of file names which match the
pattern. In a list of words specifying filename substitu-
tion 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 abbreviations.
In matching filenames, the character . at the beginning of a
filename or immediately following a /, as well as the char-
acter / 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 filename is used to
refer to home directories. Standing alone, i.e., ~ it
expands to the invokers home directory as reflected in the
value of the variable home. When followed by a name con-
sisting of letters, digits and - characters, the shell
searches for a user with that name and substitutes their
home directory; thus ~ken might expand to /usr/ken and
~ken/chmach to /usr/ken/chmach. If the character ~ is fol-
lowed by a character other than a letter or / or appears not
at the beginning of a word, it is left undisturbed.
Printed 1/15/91 Page 15
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
The metanotation a{b,c,d}e is a shorthand for abeaceade.
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 undisturbed.
Input/output
The standard input and standard output of a command may be
redirected with the following syntax:
< name
Open file name (which is first variable, command and
filename expanded) as the standard input.
<< word
Read the shell input up to a line which is identical to
word. word is not subjected to variable, filename or
command substitution, and each input line is compared
to word before any substitutions are done on this input
line. Unless a quoting \, ", ' or ' appears in word,
variable and command substitution is performed on the
intervening lines, allowing \ to quote $, \ and '.
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 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, its previous contents being lost.
If the variable noclobber is set, then the file must
not exist or be a character special file (e.g., a ter-
minal or /dev/null) or an error results. This helps
prevent accidental destruction of files. In this case
the ! forms can be used and 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 filenames
Page 16 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
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. Otherwise
similar to >.
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 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 << 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 |.
To redirect standard output and standard error to separate
files, use (cmd > file1) >& file2; /dev/tty may be used to
redirect input or output to or from your terminal.
Expressions
A number of the built-in commands (to be described subse-
quently) take expressions, in which the operators are simi-
lar to those of C, with the same precedence. These expres-
sions appear in the @, exit, if, and while commands. The
following operators are available:
|| && | ^ & == != =~ !~ <= >= < > << >> +
- * / % ! ~ ( )
Here the precedence increases to the right, ==, !=, =~ and
!~; <=, >=, < and >; << and >>; + and -; *, / and % being,
in groups, at the same level. The ==, !=, =~ and !~ opera-
tors compare their arguments as strings; all others operate
on numbers. The operators =~ and !~ are like != and ==
except that the right hand side is a pattern (which may con-
tain *, ? and instances of [...]) against which the left
hand operand is matched. This reduces the need for use of
the switch statement in shell scripts when all that is
really needed is pattern matching.
Printed 1/15/91 Page 17
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
Strings which 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; except when adja-
cent to components of expressions which are syntactically
significant to the parser (& | < > ( )) they should be sur-
rounded by spaces.
Command executions can be used as primitive operands in
expressions. When used in an expression, the command is
enclosed in { and }, e.g., {command}. Command executions
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 com-
mand should be executed outside of an expression and the
variable status examined.
File enquiries can also be used as primitive operands in
expressions. They should be of the form -l name where l is
one of:
r read access
w write access
x execute access
e existence
o ownership
z zero size
f plain file
d directory
c character special file
b block special file
p named pipe (fifo)
u set-user-ID bit is set
g set-group-ID bit is set
k sticky bit is set
s size greater than zero
t open file descriptor for terminal device
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., 0.
Control Flow
The shell contains a number of commands which 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.
Page 18 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
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 simple command on an input line
as shown below.
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 gotos
will succeed on non-seekable 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.
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 com-
mand and filename substituted. name is not allowed to be
alias or unalias.
break
Causes execution to resume after the end of the nearest
enclosing foreach or while. The remaining commands on
the current line are executed. Multi-level 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
Change the shell's working directory to directory name.
If no argument is given, then change to the home direc-
tory 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 subdirectory 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.
Printed 1/15/91 Page 19
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
continue
Continue 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
dirs -l
Prints the directory stack; the top of the stack is at
the left, the first directory in the stack being the
current directory. In the first form the user's home
directory is represented by ~.
echo wordlist
echo -n wordlist
The specified words are written to the shell's standard
output, separated by spaces, and terminated with a new-
line unless the -n option or the \c escape is specified.
The following C-like escape sequences are available:
\bbackspace
\cprint line without new-line
\fform-feed
\nnew-line
\rcarriage return
\ttab
\\backslash
\nthe character whose ASCII code is the 1-, 2- or
3-digit octal number n.
else
end
endif
endsw
See the description of the foreach, if, switch, and while
statements below.
eval arg ...
(As in sh(1).) The arguments are read as input to the
shell and the resulting command(s) executed in the con-
text of the current shell. This is usually used to exe-
cute commands generated as the result of command or vari-
able substitution, since parsing occurs before these sub-
stitutions. See tset(1) for an example of using eval.
exec command
The specified command is executed in place of the current
shell.
exit
Page 20 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
exit(expr)
The shell exits either with the value of the status vari-
able (first form) or with the value of the specified 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 com-
mand and the matching end are executed. (Both 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 to ter-
minate 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. If you
make a mistake typing in a loop at the terminal, you can
rub it out.
glob wordlist
Like echo but no \ escapes are recognized and words are
delimited by null characters in the output. Useful for
programs which wish to use the shell to filename expand a
list of words.
goto word
The specified word is filename 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. Execu-
tion continues after the specified line.
history
history n
history -r n
history -h n
Displays the history event list; if n is given only the n
most recent events are printed. The -r option reverses
the order of printout to be most recent first rather than
oldest first. The -h option causes the history list to
be printed without leading numbers. This is used to pro-
duce files suitable for sourceing using the -h option to
source.
if (expr) command
If the specified expression evaluates true, then the sin-
gle command with arguments is executed. Variable substi-
tution 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
Printed 1/15/91 Page 21
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
parenthesized command list. Input/output redirection
occurs even if expr is false, when command is not exe-
cuted (this is a bug).
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.)
kill pid
kill -sig pid ...
Sends either the TERM (terminate) signal or the specified
signal to the specified processes. Signals are either
given by number or by names (as given in
/usr/include/signal.h, stripped of the prefix SIG). There
is no default, saying just "kill" does not send a signal
to the current process.
login
Terminate a login shell, replacing it with an instance of
/bin/login. This is one way to log off, included for
compatibility with sh(1).
logout
Terminate a login shell. Especially useful 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 respec-
tively. The super-user may specify negative niceness by
using nice -number .... Command is always executed in a
sub-shell, and the restrictions place on commands in sim-
ple if statements apply.
nohup
nohup command
Page 22 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
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 & are
effectively nohuped.
onintr
onintr -
onintr label
Control the action of the shell on interrupts. The first
form restores the default action of the shell on inter-
rupts which is 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 inter-
rupt is received or a child process terminates because it
was interrupted.
In any case, if the shell is running detached and inter-
rupts are being ignored, all forms of onintr have no
meaning and interrupts continue to be ignored by the
shell and all invoked commands.
popd
popd +n
Pops the directory stack, returning to the new top direc-
tory. With an argument `+n' discards the nth entry in
the stack. The elements of the directory stack are num-
bered from 0 starting at the top.
pushd
pushd name
pushd +n
With no arguments, pushd exchanges the top two elements
of the directory stack. Given a name argument, pushd
changes to the new directory (ala cd) and pushes the old
current working directory (as in csw) onto the directory
stack. With a numeric argument, rotates the nth 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.
rehash
Causes the internal hash table of the contents of the
directories 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 only be neces-
sary if you add commands to one of your own directories,
or if a systems programmer changes the contents of one of
the system directories.
repeat count command
Printed 1/15/91 Page 23
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
The specified command which is subject to the same res-
trictions as the command in the one line if statement
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 which 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 indexth 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 filename expanded.
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.
setenv name value
Sets the value of environment variable name to be value,
a single string. The variables PATH, USER, LOGNAME,
HOME, and TERM are automatically imported to and exported
from the csh variables path, user, logname, home, and
term, respectively; there is no need to use setenv for
these.
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 performs
the same function on the specified variable.
source name
source -h 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. Normally
input during source commands is not placed on the history
list; the -h option causes the commands to be placed in
the history list without being executed.
switch (string)
case str1:
Page 24 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
...
breaksw
...
default:
...
breaksw
endsw
Each case label is successively matched against the
specified string which is first command and filename
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 execu-
tion 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 con-
tinues 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 summary as
described under the time variable is printed. If neces-
sary, an extra shell is created to print the time statis-
tic 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 be unaliased.
unhash
Use of the internal hash table to speed location of exe-
cuted programs is disabled.
unset pattern
All variables whose names match the specified pattern are
removed. Thus all variables are removed by unset *; this
has noticeably distasteful side-effects. It is not an
error for nothing to be unset.
Printed 1/15/91 Page 25
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
unsetenv pattern
Removes all variables whose name match the specified pat-
tern from the environment. See also the setenv command
and env(1).
wait
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.
while (expr)
...
end
While the specified expression evaluates non-zero, 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.
%
% user
The first form toggles the user ID and group ID between
that of root and user for all executed commands (except
built-ins). The prompt is automatically toggled between
# and #%. The second form specifies a user name, listed
in /etc/passwd, that should be toggled to and from.
@
@ 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 indexth argument of name. Both name and its indexth
component must already exist.
The operators *=, +=, etc., are available as in C. The
space separating the name from the assignment operator is
optional. Spaces are, however, mandatory in separating
components of expr which would otherwise be single words.
Special postfix ++ and -- operators increment and decre-
ment name respectively, i.e., @ i++.
Pre-defined and Environment Variables
The following variables have special meaning to the shell.
Of these, argv, cwd, home, path, prompt, shell and status
are always set by the shell. Except for cwd and status,
this setting occurs only at initialization; these variables
Page 26 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
will not then be modified unless this is done explicitly by
the user.
This shell copies the environment variable HOME into home,
and copies it 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 .cshrc as inferior csh
processes will import the definition of path from the
environment, and re-export it if you then change it.
argv Set to the arguments to the shell, it is from
this variable that positional parameters are sub-
stituted, i.e., $1 is replaced by $argv[1], etc.
cdpath Gives a list of alternate directories searched to
find subdirectories in chdir commands.
cwd The full pathname of the current directory.
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 non-
built-in commands all expansions occur before
echoing. Built-in commands are echoed before
command and filename substitution, since these
substitutions are then done selectively.
histchars Can be given a string value to change the charac-
ters used in history substitution. The first
character of its value is used as the history
substitution character, replacing the default
character !. The second character of its value
replaces the character ↑ in quick substitutions.
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 dis-
carded. Too large values of history may run the
shell out of memory. The last executed command
is always saved on the history list.
home The home directory of the invoker, initialized
from the environment. The filename expansion of
~ refers to this variable.
ignoreeof If set the shell ignores end-of-file from input
devices which are terminals. This prevents
shells from accidentally being killed by CTRL-ds.
mail The files where the shell checks for mail. This
is done after each command completion which will
Printed 1/15/91 Page 27
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
result in a prompt, if a specified interval has
elapsed. If the file exists with an access time
not greater than its modify time, the shell says
``You have new mail.''.
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 says ``New mail in name'' when there is
mail in the file name.
noclobber As described in the section on Input/output, res-
trictions are placed on output redirection to
insure that files are not accidentally destroyed,
and that >> redirections refer to existing files.
noglob If set, filename expansion is inhibited. This is
most useful in shell scripts which are not deal-
ing with filenames, or after a list of filenames
has been obtained and further expansions are not
desirable.
nonomatch If set, it is not an error for a filename expan-
sion 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., "echo [" still gives an error.
path Each word of the path variable specifies a direc-
tory in which commands are to be sought for exe-
cution. A null word specifies the current direc-
tory. If there is no path variable, then only
full path names will execute. The usual search
path is ., /bin and /usr/bin, but this may vary
from system to system. For the super-user the
default search path is /bin, /usr/bin, /etc. A
shell which is given neither the -c nor the -t
option will normally hash the contents of the
directories in the path variable 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 which is printed before each command
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 sequence \\ is replaced with a single
Page 28 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
\. The prompt should only be set by the user if
it is already defined so that it will not be
printed when processing shell scripts by using
the statement
if ( $?prompt ) set prompt='\!% '
If the sequence \@x appears, where x is one of
the characters listed below, then it will be
replaced by the current time and date in the
indicated format.
R time as HH:MM AM/PM, e.g. 8:40PM
r time as HH:MM:SS AM/PM, e.g. 08:40:25 PM
m month of year - 01 to 12
d day of month - 01 to 31
y last 2 digits of year - 00 to 99
D date as mm/dd/yy
H hour - 00 to 23
M minute - 00 to 59
S second - 00 to 59
T time as HH:MM:SS
j day of year - 001 to 366
w day of week - Sunday = 0
a abbreviated weekday - Sun to Sat
h abbreviated month - Jan to Dec
n insert a new-line character
t insert a tab character
The default prompt is %, or # for the super-user.
savehist is given a numeric value to control the number of
entries of the history list that are saved in
~/.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
~/.history into the history list enabling history
to be saved across logins. Too large values of
savehist will slow down the shell during start
up.
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 execut-
able by the system. (See the description of
Non-built-in Command Execution below.) Initial-
ized 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. Built-in commands which fail return exit
status 1, all other built-in commands set status
Printed 1/15/91 Page 29
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
0.
time Controls automatic timing of commands. If set,
then any command which takes more than this many
cpu seconds will cause a line giving user, sys-
tem, and real times and a utilization percentage
which is the 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.
Non-built-in Command Execution
When a command to be executed is found not to 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 chdir
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 an 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:
Page 30 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
-c Commands are read from the (single) following argument
which must be present. Any remaining arguments are
placed in argv.
-e The shell exits if any invoked command terminates
abnormally or yields a non-zero exit status.
-f The shell will start faster, because it will neither
search for nor execute commands from the file .cshrc in
the invokers home directory.
-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.
-n Commands are parsed, but not executed. This may aid in
syntactic checking of shell scripts.
-s Command input is taken from the standard input.
-t A single line of input is read and executed. A \ may
be used to escape the newline 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 substitu-
tion.
-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 Is to -x as -V is to -v.
After processing of flag arguments, if arguments remain but
none of the -c, -i, -s, or -t options was 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. Remaining arguments initial-
ize the variable argv. csh scripts should always start with
#! /bin/csh -f
which causes the kernel to fork off /bin/csh to process them
even if invoked by a Bourne shell user and inhibits process-
ing of the .cshrc file to prevent interference by the user's
differing aliases.
Printed 1/15/91 Page 31
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
Signal Handling
The shell normally ignores quit signals. Processes running
in background (by &) are immune to signals generated from
the keyboard, namely, interrupt and quit, and to hangups.
Other signals have the values which the shell inherited from
its parent. The handling of interrupts and terminate sig-
nals in shell scripts 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.
EXAMPLE
csh
creates a new C shell which will accept shell commands.
FILES
~/.cshrc Read at beginning of execution by each shell.
/etc/cshrc Read by login shell, after /cshrc at login.
e&~/.login Read by login shell, after .cshrc at login.
~/.logout Read by login shell, at logout.
/bin/sh Standard shell, for shell scripts not starting with a #.
/tmp/sh* Temporary file for <<.
/etc/passwd Source of home directories for ~name.
LIMITATIONS
Words can be no longer than 1024 characters. The system
limits argument lists to 5120 characters. The number of
arguments to a command which involves filename expansion is
limited to 1/6th 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 alias substitu-
tions on a single line to 20.
SEE ALSO
sh(1).
access(2), exec(2), fork(2), pipe(2), signal(2), umask(2),
wait(2), environ(5) in the Programmer's Reference Manual.
An Introduction to the C Shell, by William Joy.
ERRORS
It suffices to place the sequence of commands in parenthesis
to force it to a subshell, i.e., ( a ; b ; c ).
Control over tty output after processes are started is prim-
itive; 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 con-
trol.
Page 32 Printed 1/15/91
CSH(1-SysV) RISC/os Reference Manual CSH(1-SysV)
Alias substitution is most often used to clumsily simulate
shell procedures; shell procedures should be provided rather
than aliases.
Control structures should be parsed rather than being recog-
nized as built-in commands. This would allow control com-
mands to be placed anywhere, to be combined with |, and to
be used with & and ; metasyntax.
It should be possible to use the : modifiers on the output
of command substitutions. All and more than one : modifier
should be allowed on $ substitutions.
Bourne shell scripts which start with # will be executed by
csh unless they use the kernel's #! facility, e.g.
#! /bin/sh
AUTHOR
William Joy.
ORIGIN
4.3 BSD
Printed 1/15/91 Page 33