csh(1) CLIX csh(1)
NAME
csh - Runs a shell (command interpreter) with C-like syntax
SYNOPSIS
csh [-cefinstvVxX] [arg ... ]
DESCRIPTION
The csh command is a first implementation of a command language
interpreter incorporating a history mechanism (see History Substitutions),
job control facilities (see Jobs), interactive filename and username
completion (see Filename Completion), and a C-like syntax.
The csh command begins by executing commands from the file .cshrc in the
home directory of the invoker. If this is a login shell, it also executes
commands from the file .login there.
Normally, the shell will then begin reading commands from the terminal,
prompting with ``%''. Argument Processing 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 in &&, ||, <<, or >> these pairs form single
words. These parser metacharacters may be made part of other words, or
prevented their special meaning by preceding them with \. A newline
preceded by a \ is equivalent to a blank.
In addition, strings enclosed in matched pairs quotations, ` `, ' ', or "
", form parts of a word; metacharacters in these strings, including blanks
and tabs, do not form separate words. These quotations have semantics to
be described subsequently. Within ' ' or " ", a newline preceded by a \
gives a true newline character.
When the shell's input is not a terminal, the character # introduces a
comment that continues until the end of the input line. It does not have
this special meaning when preceded by \ and in quotations using ` `, ' ',
and " ".
2/94 - Intergraph Corporation 1
csh(1) CLIX csh(1)
Commands
A simple command is a sequence of words, with the first specifying the
command to be executed. A simple command or a sequence of simple commands
separated by | characters forms a pipeline. The output of each command in
a pipeline is connected to the input of the next. Sequences of pipelines
may be separated by ;, and are then executed sequentially. A sequence of
pipelines may be executed without immediately waiting for it to terminate
by following it with an &.
Any of the above may be placed in ( ) to form a simple command (which may
be a component of a pipeline, and so on.). Pipelines can also be
separated 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 (displayed by the jobs command) and assigns them small
integer numbers. When a job is started asynchronously with &, the shell
displays a line that looks like the following, indicating that the job
started asynchronously was job number 1 and had one (top-level) process
with process ID 1234.
[1] 1234
If a job is running and the user wishes to do something else, keying in a
<Ctrl-Z> sequence sends a STOP signal to the current job. The shell will
then normally indicate that the job has been ``Stopped'', and display
another prompt. the state of this job can then be manipulated, putting it
in the background with the bg command, or run other commands and then
eventually bring the job back to the foreground with the foreground
command fg. Keying in <Ctrl-Z> takes effect immediately and, like an
interrupt, pending output and unread input are discarded when it is typed.
A job running in the background will stop if it tries to read from the
terminal. Background jobs are normally allowed to produce output, but
this can be disabled by giving the command stty tostop. If this tty
option is set, background jobs will stop when they try to produce output
as they do when they try to read input.
Jobs in the shell can be referred to in several ways. The character %
introduces a job name. To refer to job number 1, it can be named %1.
Naming a job brings it to the foreground; thus, %1 is a synonym for fg %1,
bringing job 1 to the foreground. Similarly, saying %1 & resumes job 1 in
the background. Jobs can also be named by prefixes of the string typed to
start them if these prefixes are unambiguous; thus, %ex would normally
restart a suspended ex job, if only one suspended job's name began with
the string ``ex''. Saying %?string, which specifies a job whose text
contains string if only one such job exists, is also possible.
2 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
The shell maintains a status 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.
Status Reporting
This shell learns immediately when a process changes state. It normally
informs the user when a job becomes blocked so that no further progress is
possible. However, this information is only received just before it
displays a prompt. This is done so that it does not otherwise disturb the
user's work. If, however, the shell variable notify is set, the shell
will notify the user immediately of changes of background job status.
Also, a shell command, notify, marks a single process so that its status
changes will be immediately reported. By default, notify marks the
current process; simply entering notify after starting a background job
marks it.
When trying to leave the shell while jobs are stopped, the user will be
warned that ``You have stopped jobs.'' The jobs command may be used to see
what they are. If the user does this or immediately tries to exit again,
the shell will not give a second warning, and the suspended jobs will be
terminated.
Filename Completion
When the filename completion feature is enabled by setting the shell
variable filec (see set), csh will interactively complete filenames and
usernames from unique prefixes when they are input from the terminal
followed by the escape character ( <Esc> or <Ctrl-[>). For example, if
the current directory contains the following:
DSC.OLD bin cmd lib xmpl.c
DSC.NEW chaosnet cmtest mail xmpl.o
bench class dev mbox xmpl.out
and the input is
vi ch<Esc>
The csh command will complete the prefix ``ch'' to the only matching
filename chaosnet, changing the input line to the following:
vi chaosnet
However, given
vi D<Esc>
csh will only expand the input to
2/94 - Intergraph Corporation 3
csh(1) CLIX csh(1)
vi DSC.
and will sound the terminal bell to indicate that the expansion is
incomplete, since two filenames match the prefix ``D''.
If a partial filename is followed by the end-of-file character (usually
the <Ctrl-D> sequence), then, instead of completing the name, csh will
list all filenames matching the prefix. For example, the input
vi <Ctrl-D>
causes all files beginning with ``D'' to be listed:
DSC.NEW DSC.OLD
while the input line remains unchanged.
The same system of escape and end-of-file can also be used to expand
partial usernames if the word to be completed (or listed) begins with the
character ~. For example, typing
cd ~ro<Ctrl-D>
may produce the expansion
cd ~root
The use of the terminal bell to signal errors or multiple matches can be
inhibited by setting the variable nobeep.
Normally, all files in the directory are candidates for name completion.
Files with certain suffixes can be excluded from consideration by setting
the variable fignore to the list of suffixes to be ignored. Thus, if the
command
set fignore = (.o .out)
was entered, then typing
vi x<Esc>
would result in the completion to
vi xmpl.c
ignoring the files xmpl.o and xmpl.out. However, if the only completion
possible requires not ignoring these suffixes, they are not ignored. In
addition, fignore does not affect the listing of filenames by using the
<Ctrl-D> sequence. All files are listed regardless of their suffixes.
Substitutions
4 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
We now describe the various transformations the shell performs 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 prevent its special meaning; for convenience, a ! is
passed unchanged when it is followed by a blank, tab, newline, = or (.
(History substitutions also occur when an input line begins with ^. This
special abbreviation will be described later.) Any input line that
contains history substitution is echoed on the terminal before it is
executed as it could have been typed without history substitution.
Commands input from the terminal that consist of one or more words are
saved on the history list. The history substitutions reintroduce
sequences of words from these saved commands in the input stream. The
size of the history list is controlled by the history variable; the
previous command is always retained, regardless of its value. Commands
are numbered sequentially from 1.
For definiteness, the following output from the history command should be
considered:
09 write michael
10 ex write.c
11 cat oldwrite.c
12 diff *write.c
The commands are shown with their event numbers. Using even numbers is
usually not necessary, but the current event number can be made part of
the prompt by placing an ! in the prompt string.
With the current event 13, previous events can be referred to by event
number as in ! 11, relatively as in ! -2 (referring to the same event), by
a prefix of a command word as in ! d for event 12 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
reintroduce 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.
To select words from an event, The event specification can be followed by
a : and a designator for the desired words. The words of an input line
are numbered from 0, the first (usually a command) word being 0, the
second word (first argument) being 1, and so on. The basic word
designators are as follows:
2/94 - Intergraph Corporation 5
csh(1) CLIX csh(1)
0 First (command) word
n nth argument
^ First argument, that is, 1
$ Last argument
% Word matched by (immediately preceding) ?s? search
x-y Range of words
-y Abbreviates 0-y
* Abbreviates ^-$, or nothing if only 1 word in event
x* Abbreviates x-$
x- Like x* but omitting word $
The : 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:
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/l/r/ Substitute l for r.
t Remove all leading pathname components, leaving the tail.
& Repeat the previous substitution.
g Apply the change globally, prefixing the above, as in g&.
p Display 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, an error results when no word is
applicable.
The left-hand side of substitutions are not regular expressions in the
sense of the editors, but rather strings. Any character may be used as
6 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
the delimiter in place of /; a \ quotes the delimiter in the l and r
strings. The character & 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 an l or from a contextual scan string s in !?s?. The trailing
delimiter in the substitution may be omitted if a newline follows
immediately as the trailing ? may in a contextual scan.
A history reference may be given without an event specification, that is,
!$. In this case, the previous command is being referenced unless a
previous history reference occurred on the same line. In this case, the
form repeats the previous 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 short-hand 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 follow. Thus, after
ls -ld ~paul, !{l}a could be used to do ls -ld ~paula, while !la would
look for a command starting with la.
Quotations With Single And Double Quotes
Quoting by ' ' and " " can prevent all or some remaining substitutions.
Strings enclosed in ' ' are prevented from any further interpretation.
Strings enclosed in " " may be 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 Substitution 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 established, 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,
the text that is the alias for that command is reread with the history
mechanism available as though that command were the previous line input.
The resulting words replace the command and argument list. If the history
list is not referred to, the argument list is unchanged.
Thus, if the alias for ``ls'' is ``ls -l'' the command ls /usr would map
to ls -l /usr; the argument list would not be disturbed. Similarly if the
alias for ``lookup'' was ``grep !^ /etc/passwd'', 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
2/94 - Intergraph Corporation 7
csh(1) CLIX csh(1)
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, alias print 'pr \!|* | lpr' can be done to make a command that pr's
its arguments to the line printer.
Variable Substitution
The shell maintains a set of variables. Each variable has a list of zero
or more words as a value. 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 flag.
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 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 as keyed by $ characters.
This expansion can be prevented by preceding the $ with a \ except within
" ", where it always occurs, and within ' ', 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. Thus, the first (command) word to
this point can generate more than one word. The first word becomes the
command name, and the rest become arguments.
Unless enclosed in " " or given the :q modifier the results of variable
substitution may eventually be command and filename substituted. Within "
", a variable whose value consists of multiple words expands to a (portion
of) a single word, with the words of the variable 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.
8 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
The following metasequences are provided for introducing variable values
into the shell input. Except as noted, referring to a variable that is
not set results in an error.
$name
${name}
These are replaced by the words of the value of variable name, each
separated by a blank. Braces insulate name from following
characters that would otherwise be part of it. Shell variables
have names with up to 20 letters and digits starting with a letter.
The underscore character 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 $ substitution 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.
An empty range is not an error if the second argument is omitted or
is 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].
$* 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, the
modifiers must appear within the braces. The current implementation
allows only one : modifier for 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.
2/94 - Intergraph Corporation 9
csh(1) CLIX csh(1)
$?0 Substitutes 1 if the current input filename is known, 0 if it
is not.
$$ Substitutes the (decimal) process number of the (parent) shell.
$< Substitutes a line from stdin, with no further interpretation.
It can be used to read from the keyboard in a shell script.
Command And Filename Substitution
The remaining substitutions, command and filename substitution, are
applied selectively to the arguments of built-in commands. Thus, portions
of expressions not evaluated are subject to these expansions. For
commands 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 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 discarded. This text then
replaces the original string. Within " ", only newlines force new words;
blanks and tabs are preserved.
In any case, the final newline does not force a new word. Thus, a command
substitution can yield only part of a word even if the command outputs a
complete line.
If a word contains *, ?, [, or { or begins with the character ~, the 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 filenames that match the pattern. In a list
of words specifying filename substitution, no pattern matching an existing
filename results in as error, but it is not required for each pattern to
match. Only the metacharacters *, ?, and [ imply pattern matching. The
characters ~ and { being more like abbreviations.
In matching filenames, the character . at the beginning of a filename or
immediately following a /, and the character / must be matched explicitly.
The character * matches any character string, 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 character lexically between the two.
The character ~ at the beginning of a filename refers to home directories.
Standing alone (``~''), it expands to the invokers 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 their home directory; thus, ~ken might
expand to /usr/ken and ~ken/chmach to /usr/ken/chmach. If ~ is followed
by a character other than a letter or / or does not appear at the
beginning of a word, it is undisturbed.
10 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
The metanotation a{b,c,d}e is shorthand for abe ace ade. Left to right
order is preserved, and results of matches are sorted separately at a low
level to preserve this order. This construct may be nested. Thus,
~src/s1/{oldls,ls}.c expands to /usr/src/s1/oldls.c /usr/src/s1/ls.c
whether or not these files exist with no chance of error if the home
directory for src is /usr/src. 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 {} pass undisturbed.
Input/Output
The stdin and stdout of a command may be redirected with the following
syntax:
< name Open file name (which is first variable, command and filename
expanded) as stdin.
<< 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 performed 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 that are substituted have all
blanks, tabs, and newlines preserved, except for the final
newline, which is dropped. The resulting text is placed in an
anonymous temporary file given to the command as stdin.
> name
>! name
>& name
>&! name The file name is used as stdout. If the file does not exist,
it is created; if the file exists, it is truncated and
previous content is lost.
If the variable noclobber is set, the file must not exist or
be a character special file (that is, a terminal 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 to the
specified file and stdout. The command name is expanded as <
input filenames are.
>> name
>>& name
>>! name
>>&! name Uses file name as stdout 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
2/94 - Intergraph Corporation 11
csh(1) CLIX csh(1)
given. It is otherwise similar to >.
A command receives the environment the shell was invoked in 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 cannot access the text of the commands by default. Instead, they
receive the original stdin 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.
Note that the default stdin for a command run detached is not modified to
be the empty file /dev/null; rather, stdin remains the original stdin of
the shell. If this is a terminal and if the process attempts to read from
the terminal, the process will block and the user will be notified (see
Jobs above).
Diagnostic output may be directed through a pipe with stdout. To do so,
the form |& rather than | should be used.
Expressions
A number of the built-in commands (to be described subsequently) take
expressions, in which the operators are similar to those of C, with the
same precedence. These expressions appear in the @, exit, if, and while
commands. The following operators are available:
|| && | ^ & = = != =~ !~ <= >= < > << >> + - * / % ! ~ ( )
Here the precedence increases to the right, = =, !=, =~, and !~; <=, >=,
<, and >; << and >>; + and -; and *, /, and % being, in groups, at the
same level. The ==, !=, =~, and !~ operators 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 (containing, for
example, *s, ?s, and instances of [ ... ]) that the left-hand operand is
matched against. This reduces the need to use the switch statement in
shell scripts when only pattern matching is needed.
Strings that begin with 0 are octal numbers. Null or missing arguments
are 0. The result of all expressions are strings, which represent decimal
numbers. No two components of an expression can appear in the same word.
When adjacent to components of expressions syntactically significant to
the parser (&, |, (, ), <, >) they should be surrounded by spaces.
Also available in expressions as primitive operands are command executions
enclosed in { and } and file inquiries of the form -l name, where l is one
of the following:
r read access
w write access
x execute access
12 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
e existence
o ownership
z zero size
f plain file
d directory
The specified name is command and filename expanded and then tested for
the specified relationship to the real user. If the file does not exist
or is inaccessible, all inquiries return false (0). Command executions
succeed, returning true (1), if the command exits with status 0.
Otherwise, they fail, returning false (0). If more detailed status
information is required, the command should be executed outside of an
expression and the variable status should be examined.
Control Flow
The shell contains a number of commands used to regulate the flow of
control in command files (shell scripts) and (in limited but useful ways)
from terminal input. These commands 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, and the if-then-else form of
the if statement require the major keywords to appear in a single simple
command on an input line as shown below.
If the shell's input is not seekable, the shell buffers input whenever a
loop is 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 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, it is executed in a
subshell.
alias [name [wordlist]]
If no arguments are given, displays all aliases. If just name is
given, displays the alias for name. Otherwise, assigns the
specified wordlist as the alias of name; wordlist is command and
filename substituted. Name cannot be ``alias'' or ``unalias.''
alloc Shows the amount of dynamic memory acquired, broken into used and
free memory. With any argument, shows the number of free and used
blocks in each size category. The categories start at size 8 and
double at each step. This command's output may vary across system
2/94 - Intergraph Corporation 13
csh(1) CLIX csh(1)
types.
bg [%job ... ]
Puts the current or specified jobs in the background, continuing
them if they are stopped.
break Causes execution to resume after the end of the nearest enclosing
foreach or while. 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 [name]
chdir [name]
Change the shell's working directory to directory name. If no
argument is given, change to the home directory. If name is not
found as a subdirectory of the current directory (and does not
begin with /, ./ or ../), 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 /, the
name is tried to see if it is a directory.
continue
Continue execution of the nearest enclosing while or foreach. The
remaining commands on the current line are executed.
default:
Labels the default case in a switch statement. The default should
follow all case labels.
dirs Displays the directory stack. The top of the stack is at the left.
The first directory in the stack is the current directory.
echo [-n] wordlist
The specified words are written to the shell's stdout, separated by
spaces, and terminated with a newline unless the -n flag is
specified.
else
end
endif
endsw See the description of the foreach, if, switch, and while
statements below.
eval arg ...
(As in sh.) The arguments are read as input to the shell and the
14 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
resulting command(s) executed in the context of the current shell.
This is usually used to execute commands generated as the result of
command or variable substitution, since parsing occurs before these
substitutions. See tset for an example of using eval.
exec command
The specified command is executed in place of the current shell.
exit[(expr)]
If expr is not given, the shell exits with the value of the status
variable. Otherwise, the shell exits with the value of the
specified expr.
fg [%job ... ]
Brings the current or specified jobs to the foreground, continuing
them if they are stopped.
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 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 once, prompting with ``?'' before any statements in
the loop are executed. If a mistake is made while typing in a loop
at the terminal, it can be erased.
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 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 with the form label:, possibly
preceded by blanks or tabs. Execution continues after the
specified line.
history [-rh] [n]
Displays the history event list. If n is given, only the n most
recent events are displayed. The -r flag reverses the order of
display so that the most recent is first, not the oldest. The -h
flag displays the history list without leading numbers. This will
produce files suitable for sourcing using the -h flag to source.
if (expr) command
2/94 - Intergraph Corporation 15
csh(1) CLIX csh(1)
If the specified expression evaluates true, the single command with
arguments is executed. Variable substitution on command happens
early, when 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 and command is not executed. (This is a bug.)
if (expr) then
...
[else if (expr2) then]
...
[else]
...
endif If the specified expr is true, the commands to the first else are
executed; otherwise, if expr2 is true, the commands to the second
else are executed, and so on. Any number of else-if pairs are
possible; only one endif is needed. The else is 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 [-l]
Lists the active jobs. With the -l flag, it lists process IDs in
addition to the normal information.
kill [-l] [-sig] [%job ... ] [pid ... ]
Sends either the TERM (terminate) signal or the specified signal to
the specified jobs or processes. Signals are either given by
number or by names (as given in <signal.h>, without the prefix
SIG). The signal names are listed by kill -l. This command has no
default. Therefore, using only kill will not send a signal to the
current job. If the signal being sent is TERM (terminate) or HUP
(hangup), the job or process will be sent a CONT (continue) signal
as well.
limit [-h] [resource] [maximum-use]
Limits the consumption by the current process and each process it
creates so that it does not individually exceed maximum-use on the
specified resource. If no maximum-use is given, the current limit
is displayed; if no resource is given, 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 ceiling 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.
The resource that can currently be controlled is filesize (the
largest single file which can be created).
The maximum-use may be given as a (floating-point or integer)
number followed by a scale factor. The default scale is k or
kilobytes (1024 bytes). A scale factor of m or megabytes may also
16 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
be used.
For both resource names and scale factors, unambiguous prefixes of
the names suffice.
login Terminate a login shell, replacing it with an instance of
/bin/login. This method for logging off is compatible with sh.
logout Terminate a login shell. Especially useful if ignoreeof is set.
nohup [command]
Without a command, nohup can be used in shell scripts to ignore
hangups for the remainder of the script. Specifying a command runs
the command with hangups ignored. All processes detached with &
are effectively nohuped.
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 [label]
Control the action of the shell on interrupts. With no flags,
onintr restores the default action of the shell on interrupts,
which is to terminate shell scripts or to return to the terminal
command input level. The form onintr - causes all interrupts to be
ignored. The form onintr label causes the shell to execute a goto
label when an interrupt is received or a child process terminates
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.
popd [+n]
Pops the directory stack, returning to the new top directory. With
an argument +n, this discards the nth entry in the stack. The
elements of the directory stack are numbered from 0 starting at the
top.
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) on the directory stack. With a numeric argument, rotates
the nth argument of the directory stack to be the top element and
changes to it. The members of the directory stack are numbered
from the top starting at 0.
2/94 - Intergraph Corporation 17
csh(1) CLIX csh(1)
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 the user is
logged in. This should only be necessary if commands are added to
one of the user's directories or if a systems programmer changes
the contents of one of the system directories.
repeat count command
The specified command, subject to the same restrictions 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 [name[[index]]=word ... ]
set name=(wordlist) ...
With no flags, shows the value of all shell variables. Variables
that have more than a single word as a value display as a
parenthesized word list. The form set name sets name to the null
string. The form set name=word sets name to the single word. The
form set name[index]=word sets the indexth component of name to
word; this component must exist. The form set name=(wordlist) sets
name to the list of words in wordlist. The value is command and
filename expanded.
These arguments may be repeated to set multiple values in a single
set command. However, variable expansion happens for all arguments
before any setting occurs.
setenv [name [value]]
With no flags, setenv lists all current environment variables.
When only name given, it is set to an empty string. If both name
and value are given, the value of environment variable name is set
to value, a single string. The most commonly-used environment
variables USER, TERM, and PATH are automatically imported to and
exported from the csh variables user, term, and path; setenv is not
needed for these.
shift [variable]
The members of argv are shifted to the left, discarding argv[1].
argv must be set and have one word or more for a value. If
variable is given, shift performs the same function on the
specified variable.
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 flag causes the commands to
be placed in the history list without being executed.
stop [%job ... ]
18 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
Stops the current or specified job executing in the background.
suspend
Causes the shell to stop as if it had been sent a stop signal with
the <Ctrl-Z> sequence. This is most often used to stop shells
started by su.
switch (string)
case str1:
...
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 no labels match before a default
label is found, 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.
umask value
The file creation mask is either displayed if no argument is given
or set to the specified value. 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, and 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 Using the internal hash table to speed location of executed
programs is disabled.
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 use
this.
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
2/94 - Intergraph Corporation 19
csh(1) CLIX csh(1)
unset.
unsetenv pattern
Removes all variables whose names match the specified pattern from
the environment. See the setenv command above.
wait Waits for all background jobs. If the shell is interactive, an
interrupt can disrupt the wait. At this time the shell displays
names and job numbers of all jobs known to be outstanding.
while (expression)
...
end While the specified expression evaluates to be 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 to the foreground.
%job & Continues the specified job in the background.
@ [name[[index]]=expr]
With no flags, displays the values of all shell variables. The
form @ name=expr sets the specified name to the value of expr. If
the expression contains <, >, &, or |, this part of the expression
must be placed in ( ). The form @ name[index]=expr assigns the
value of expr to the index'th argument of name. Both name and its
indexth component must exist.
The operators *=, +=, etcetera are available as they are in C. The
space separating the name from the assignment operator is optional.
Spaces are, however, mandatory in separating components of expr
that would otherwise be single words.
Special postfix ++ and ~~ operators increment and decrement name,
respectively, for example, @ i++.
Predefined and Environment Variables
The following variables have special meaning to the shell. Of these,
argv, cwd, home, path, prompt, shell, and status, the shell always sets.
Except for cwd and status, this setting occurs only at initialization;
these variables will not then be modified unless done explicitly by the
user.
This shell copies the environment variable USER in the variable user, TERM
in term, and HOME in home and copies these back in the environment when
the normal shell variables are reset. The environment variable PATH is
likewise handled; it is not necessary to worry about setting it other than
20 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
in the file .cshrc, as inferior csh processes will import path's
definition from the environment, and re-export it if it is changed.
argv Set to the arguments to the shell, it is from this variable
that positional parameters are substituted, that is, $1 is
replaced by $argv[1], and so on.
cdpath Lists alternate directories searched to find subdirectories in
chdir commands.
cwd The full pathname of the current directory.
echo Set when the -x command line flag is given. Echoes each
command and its arguments just before it is executed. For
nonbuilt-in commands, all expansions occur before echoing.
Built-in commands are echoed before command and filename
substitution, since these substitutions are then performed
selectively.
filec Enable filename completion.
histchars Can be assigned a string value to change the characters used
in history substitution. The first character of its value is
the history substitution character, replacing the default
character !. The second character replaces the character ^ in
quick substitutions.
history Can be assigned a numeric value to control the size of the
history list. Any command referenced in this many events will
not be discarded. 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 invoker's home directory, initialized from the
environment. The filename expansion of ~ refers to this
variable.
ignoreeof Causes the shell to ignore end-of-file from input devices that
are terminals. This prevents shells from accidentally being
killed by using the <Ctrl-D> sequence.
mail The files where the shell checks for mail. The check is done
after each command completion that results in a prompt, if a
specified interval has elapsed. The shell says ``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 mail checking interval, in seconds, that differs
from the default, which is 10 minutes.
2/94 - Intergraph Corporation 21
csh(1) CLIX csh(1)
If multiple mail files are specified, the shell says ``New
mail in name'' when mail is in the file name.
noclobber As described in the Input/Output section, output redirection
is restricted to ensure 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 that do not deal 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 expansion to not
match any existing files; rather, the primitive pattern is
returned. However, the primitive pattern still may not be
malformed (for example, echo [ still gives an error).
notify If set, the shell notifies the user of job completions
asynchronously. The default is to present job completions
just before displaying 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
variable, only full pathnames will execute. The usual search
path is ., /bin, and /usr/bin, but this may vary from system
to system. For the superuser the default search path is /etc,
/bin, and /usr/bin. A shell given neither the -c nor the -t
flag 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, the rehash command may
need to be executed or the commands may not be found.
prompt The string displayed before each command is read from
interactive terminal input. If a ! appears in the string it
will be replaced by the current event number unless a
preceding \ is given. Default is ``% ''. (``# '' for the
superuser.)
savehist The numeric value that controls the number of entries in the
history list that are saved in ~/.history when the user logs
out. Any command referenced in this many events will be
saved. During startup, the shell sources ~/.history into the
history list, enabling history to be saved across logins.
Excessively large values of savehist will slow down the shell
during startup.
shell The file in which the shell resides. This is used in forking
shells to interpret files with execute bits set, but cannot be
executed by the system. (See the description of Nonbuilt-in
22 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
Command Execution below.) It is initialized to the (system-
dependent) home of the shell.
status The status returned by the last command. If it terminated
abnormally, 0200 is added to the status. Built-in commands
that fail set status to 1. All other built-in commands set
status to 0.
time Controls automatic timing of commands. If set, any command
that takes more than this many cpu seconds will cause a line
giving user, system, and real times and a utilization
percentage, which is the ratio of user plus system times to
real time to be displayed when it terminates.
verbose Set by the -v command line flag, causes the words of each
command to be displayed after history substitution.
Nonbuilt-in Command Execution
When a command to be executed is not a built-in command, the shell
attempts to execute the command using execve. 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 flag, 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 is present in the search path. If this mechanism is turned
off (through unhash), or if the shell has a -c or -t argument, and in any
case for each directory component of path that does not begin with a /,
the shell concatenates with the given command name. The concatenation
forms a pathname of a file that it then attempts to execute.
Parenthesized commands are always executed in a subshell. Thus, (cd ;
pwd) ; pwd displays the home directory, but the current directory is
unchanged (displaying the current directory after the home directory). cd
; pwd changes the current directory to the home directory. Parenthesized
commands are most often used to prevent chdir from affecting the current
shell.
If the file has execute permission but is not an executable binary to the
system, it is assumed to be a file containing 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 pathname of the shell (that is, $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
2/94 - Intergraph Corporation 23
csh(1) CLIX csh(1)
If argument 0 to the shell is -, this is a login shell. The flag
arguments are interpreted as follows:
-b This flag forces a ``break'' from flag processing, causing any
further shell arguments to be treated as nonflag arguments. The
remaining arguments will not be interpreted as shell flags. This may
be used to pass flags to a shell script without confusion or possible
subterfuge. The shell will not run a set-user ID script without this
flag.
-c Commands are read from the (single) following argument that must be
present. Any remaining arguments are placed in argv.
-e The shell exits if any invoked command terminates abnormally or
yields a nonzero exit status.
-f The shell will start faster because it will neither search for nor
execute commands from the file .cshrc in the invoker's 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
flag if their input and output are terminals.
-n Commands are parsed, but not executed. This aids in syntactic
checking of shell scripts.
-s Command input is taken from stdin.
-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. This variable causes command
input to be 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 before .cshrc is executed.
-X Causes the echo variable to be set before .cshrc is executed.
After flag argument processing, if arguments remain but no -c, -i, -s, or
-t flags is given, the first argument is interpreted as the name of a
command file to be executed. The shell opens this file and saves its name
for possible resubstitution by $0. Since many systems use the standard
version 6 or version 7 shells whose shell scripts are not compatible with
this shell, the shell will execute such a ``standard'' shell if the first
character of a script is not # (if the script does not start with a
comment). Remaining arguments initialize the variable argv.
24 Intergraph Corporation - 2/94
csh(1) CLIX csh(1)
Signal Handling
The shell normally ignores quit signals. Jobs running detached (either by
& or the bg or % ... & commands) are immune to signals generated from the
keyboard, including hangups. Other signals have the values the shell
inherited from its parent. The shell's handling of interrupt and
terminate signals 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. Interrupts are never
allowed when a login shell is reading the file .logout.
FILES
~/.cshrc
read at beginning of execution by each shell
~/.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
NOTES
When a command is restarted from a stop, the shell displays the directory
it started in if it differs from the current directory. This can be
misleading as the job may have changed directories internally.
Shell built-in functions cannot be stopped or restarted. Command
sequences with the form a ; b ; c are also not handled gracefully when
stopping is attempted. If b is suspended, 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 () to force it
to a subshell, that is, ( a ; b ; c ).
Tty output control after processes are started is primitive; a good
virtual terminal interface with improved output control is needed. In a
virtual terminal interface much more interesting things could be done with
output control.
Alias substitution is most often used to clumsily simulate shell
procedures; shell procedures should be provided rather than aliases.
2/94 - Intergraph Corporation 25
csh(1) CLIX csh(1)
Commands within loops (prompted for by ``?'') are not placed in the
history list. Control structure should be parsed rather than recognized
as built-in commands. This would allow control commands 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 (at least more than one) : modifiers should be allowed
for $ substitutions.
Implementation of the filec facility is ugly and expensive.
Words can be no longer than 1024 characters. The system limits argument
lists to 12K characters. The number of arguments to a command that
involves filename expansion is limited to 1/6 the number of characters
allowed in an argument list. Command substitutions may substitute no more
characters than those allowed in an argument list. To detect looping, the
shell restricts the number of alias substitutions on a single line to 20.
RELATED INFORMATION
Commands: sh(1)
Functions: signal(2), sigset(2), killpg(2), umask(2), wait(2), access(2),
fork(2), pipe(2), ulimit(2)
Files: termio(7)
Miscellany: environ(4)
26 Intergraph Corporation - 2/94