csh
PURPOSE
Interprets commands read from a file or entered from the
keyboard.
SYNOPSIS
csh [ -cefinstvVxX ] [ arg ... ]
DESCRIPTION
The csh command is a system command interpreter and pro-
gramming language that incorporates a history mechanism
and a C-like syntax. Like the sh command, it is an ordi-
nary user program that reads commands typed at the key-
board and arranges for their execution. In addition, it
can read commands from a file, usually called a shell
procedure or a command file.
When you run csh, it begins by executing commands from
the file .cshrc in your home directory, if it exists.
If, on the other hand, csh runs as a login shell, it exe-
cutes commands from your .cshrc file and your .login
file.
Commands
A simple command is a sequence of words separated by
blanks or tabs. A word is a sequence of characters
and/or numerals that does not contain unquoted blanks.
In addition, the following characters and doubled charac-
ters also form single words when used as command separa-
tors or terminators:
& | ; < > ( )
&& || << >>
These special characters may be parts of other words.
Preceding them with a \ (backslash), however, prevents
the shell from interpreting them as special characters.
When the shell is not reading input from a work station,
it treats any word that begins with a "#" (number sign)
as a comment and ignores that word and all characters
following up to the next new-line character. Strings
enclosed in matched pairs of quotation characters or
grave accents ("' '", "" "", or "` `") can also form
parts of words. (Blanks, tab characters, and special
characters do not form separate words when they are found
within these quotation marks.) In addition, within pairs
of single quotation marks ("' '") and double quotation
marks ("" ""), you may include the new-line character by
preceding it with \ (backslash).
The first word in the simple-command sequence (numbered
0), usually specifies the name of a command. Any
remaining words, with a few exceptions, are passed to
that command. If the command specifies an executable
file that is a compiled program, the shell immediately
runs that program. If the file is marked executable but
is not a compiled program, the shell assumes that it is a
shell procedure. In this case it spawns another instance
of itself (a subshell), to read the file and execute the
commands included in it.
A pipeline is a sequence of one or more commands sepa-
rated by a "|" (vertical bar). The output of each
command in a pipeline provides the input to the next
command.
A list is a sequence of one or more pipelines separated
by a ";" (semicolon), "&" (ampersand), "&&" (two amper-
sands), or "||" (two vertical bars) and optionally ended
by a ";" (semicolon) or an "&" (ampersand). These sepa-
rators and terminators have the following effects:
; Causes sequential execution of the preceding pipe-
line (the shell waits for the pipeline to finish).
& Causes asynchronous execution of the preceding
_
pipeline (the shell does not wait for the pipeline
to finish).
&& Causes the list following it to be executed only if
__
the preceding pipeline returns a zero exit value.
|| Causes the list following it to be executed only if
the preceding pipeline returns a nonzero exit
value.
Note: The cd command is an exception. If it
returns a nonzero exit value, no subsequent com-
mands in a list are executed, regardless of the
separators.
The ";" and "&" separators have equal precedence, as do
"&&" and "||". The single-character separators have
lower precedence than the double-character separators. A
unquoted new-line character following a pipeline func-
tions the same as a ";" (semicolon). Place any of the
above in parentheses to form a simple command.
The shell associates a job with each pipeline. It keeps
a table of current jobs and assigns them small integer
numbers. When you start a job asynchronously by termi-
nating the command with a "&", the shell displays a line
that looks like the following:
[1] 1234
This line indicates that the job number is "1" and that
the job is composed of one process with a process-ID of
"1234". Use the built-in jobs command (page ) to see
what jobs are currently running.
A job running in the background competes for input if it
tries to read from the work station. Background jobs can
also produce output that competes for the work station
and is interleaved there with the output of other jobs.
There are several ways to refer to jobs in the shell.
Use the "%" (percent) character to introduce a job name.
This name can be either the job number or the command
name that started the job, if this name is unique. So,
for example, if a make process is running as job 1, you
can refer to it as "%1". You can also refer to it as
"%make", if there is only one suspended job with a name
that begins with the string "make". You can also use
%?:string
to specify a job whose name contains string, if there is
only one such job.
The shell detects immediately whenever a process changes
state. Whenever a job becomes blocked so that further
progress is not possible, a message is sent to the work
station, but not until just before the shell prompt. If,
however, the notify shell variable is set (see page ),
the shell issues a message that indicates changes in
status of background jobs immediately. Use the notify
built-in command (page ) to mark a single process so that
its status changes are immediately reported. By default,
notify marks the current process.
History Substitution
History substitution lets you modify individual words
from previous commands to create new commands, thus
making it easy to repeat commands, repeat the arguments
of a previous command in the current command, or fix
spelling mistakes in the previous command with little
typing.
History substitutions begin with the "!" (exclamation)
character and may appear anywhere on the command line,
provided they do not nest (in other words, a history sub-
stitution cannot contain another history substitution).
You can precede the "!" with a \ to prevent its special
meaning. In addition, if you place the "!" before a
blank, tab, new-line character, "=" (equal sign), or "("
(left parenthesis), it is passed unchanged. History sub-
stitutions also occur when you begin an input line with a
"^" (circumflex). (This special abbreviation is dis-
cussed on page .) The shell echoes any input line con-
taining history substitutions at the work station before
it executes that line.
The history list saves commands that the shell reads from
the work station and that consist of one or more words.
History substitution reintroduces sequences of words from
these saved commands into the input stream.
The history shell variable (page ) controls the size of
the history list. You must set the history shell vari-
able either in the .cshrc file or on the command line
with the built-in set command (page ). The previous
command is always retained, however, regardless of the
value of history. Commands in the history list are num-
bered sequentially starting from 1. The built-in history
command (page ) produces output of the type:
9 write michael
10 ed write.c
11 cat oldwrite.c
12 diff *write.c
The command strings are shown with their event numbers.
It is not usually necessary to use event numbers to refer
to events, but you can have the current event number dis-
played as part of your system prompt by placing an "!" in
the prompt string assigned to the prompt environmental
variable (page ).
A full history reference contains an event specification,
a word designator, and one or more modifiers in the fol-
lowing general format:
event[:]word:modifier[:modifier] . . .
Note: Only one word can be modified. A string that con-
tains blanks is not allowed.
In the previous sample of history command output, the
current event number is 13. Using this example, the fol-
lowing refer to previous events:
Event Specification
!10 Refers to event number 10
___
!-2 Refers to event number 11 (the current event
___
minus 2)
!d Refers to a command word beginning with "d" (in
__
this case event number 12)
!?mic? Refers to a command word that contains the
______
string "mic" (in this case, event number 9).
These forms, without further modification, simply rein-
troduce the words of the specified events, each separated
by a single blank. As a special case, "!!" refers to the
previous command; the command "!!" alone on an input line
reruns the previous command.
To select words from an event, follow the event specifi-
cation with a : (colon) and one of the following word
designators (the words of an input line are numbered
sequentially starting from 0):
Word Designator
0 The first word (the command name)
_
n The nth argument
^ The first argument
$ The last argument
_
% The word matched by an immediately preceding
_
"?string?" search
x-y A range of words from the xth word to the yth
word
-y A range of words from the first word ("0") to
the yth word
* The first through the last argument, or nothing
_
if there is only one word (the command name) in
the event
x"*" The xth through the last argument
x- Like x"*" but omitting the last word.
You may omit the colon that separates the event specifi-
cation from the word designator if the word designator
begins with a "^", "$", "*", "-", or "%". You can also
place a sequence of the following modifiers after the
optional word designator, each preceded by a colon:
Modifier
h Remove a trailing path name extension, leaving
the head.
r Remove a trailing ".xxx" component, leaving the
root name.
e Remove all but the trailing extension ".xxx."
s/l/r/ Substitute l for r. With substitutions, it is
an error for no word to be applicable.
The l (left) side of a substitution is not a
pattern in the sense of a string recognized by
an editor; rather, it is a word, a single unit
without blanks. Normally, a / (slash) delimits
the word (l) and its replacement (r). However,
you can use any character as the delimiter if
you precede that character with a \ (back-
slash). Thus, in the following example:
s\%/usr/myfile\%/usr/yourfile\%
the "%" becomes the delimiter allowing you to
include the / in your word. If you include an
"&" in the replacement, it is replaced by the
text from the left-hand side (l). A null l
side is replaced by either the last substi-
tution or by the last string used in the con-
textual scan "!?string?". You may omit the
trailing delimiter ("/") if a new-line char-
acter follows immediately.
t Remove all leading path name components,
leaving the tail.
& Repeat the previous substitution.
g Apply the change globally, that is, g&.
p Display the new command, but do not run it.
q Quote the substituted words, thus preventing
further substitutions.
x Act like q, but break into words at blanks,
tabs, and new-line characters.
Unless the modifier is preceded by a g, the change
applies only to the first modifiable word.
If you give a history reference without an event specifi-
cation, for example, "!$", the shell uses the previous
command as the event, unless a previous history reference
occurs on the same line, in which case it repeats the
previous reference. Thus, the following sequence:
!?foo?^ !$
gives the first and last arguments of the command that
matches "?foo?".
A special abbreviation of a history reference occurs when
the first nonblank character of an input line is a "^"
(circumflex). This is equivalent to "!:s^", thus pro-
viding a convenient shorthand for substitutions on the
text of the previous line. The command "^lb^lib" cor-
rects the spelling of lib in the previous command.
You can enclose a history substitution in "{}" (braces),
if necessary, to insulate it from the characters that
follow. For example, if you want to use a reference to
the command:
ls -ld ~paul
to perform the command:
ls -ld ~paula
use the following:
!{l}a
whereas "!la" would look for a command starting with
"la".
Quoting with Single and Double Quotes
Enclose strings in single and double quotation marks to
prevent all or some of the substitutions that remain.
Enclosing strings in single quotation marks ("' '") pre-
vents any further interpretation. Enclosing strings in
double quotation marks ("" "") allows further expansion.
In both cases, the text that results becomes (all or part
of) a single word. Only in one special case does a
string quoted by "" "" yield parts of more than one word;
strings quoted by "' '" never do (see "Command Substi-
tution").
Command and File Name Substitution
The shell performs command and file-name substitutions
selectively on the arguments of built-in commands. This
means that it does not expand those parts of expressions
that are not evaluated. For nonbuilt-in commands, the
shell substitutes the command name separately from the
argument list. This occurs very late, after it performs
input/output redirection and in a child of the main
shell.
COMMAND SUBSTITUTION: The shell performs command substi-
tution on a command string enclosed in grave accents
(` `). The shell normally breaks the output from such a
command into separate words at blanks, tabs, and new-line
characters; this text then replaces the original command
string. Within strings surrounded by double quotation
marks ("" ""), the shell treats only the new-line char-
acter as a word separator, thus preserving blanks and
tabs within the word.
In any case, the single final new-line character does not
force a new word. Note that it is therefore possible for
command substitution to yield only part of a word, even
if the command outputs a complete line.
FILE-NAME SUBSTITUTION: If a word contains any of the
characters "*", "?", "[", or "{", or begins with the "~"
character, then that word is a candidate for file name
substitution, also known as globbing. This word is then
regarded as a pattern and replaced with an alphabetically
sorted list of file names which match the pattern.
The current collating sequence is used, which may be
specified by the environment variables NLCTAB or NLFILE.
In a list of words specifying file name substitution, it
is an error for no patterns to match an existing file
name, but it is not required that each pattern match.
Only the character-matching symbols "*", "?", and "["
imply pattern matching; the characters "~" and "{" being
more related to abbreviations.
In matching file names, the character "." (dot) at the
beginning of a file name or immediately following a "/",
and the character "/", must be matched explicitly. The
"*" character matches any string of characters, including
the null string. The "?" character matches any single
character. The sequence [abcd] matches any one of the
enclosed characters. Within "[]", a lexical range of
characters may be indicated by [a-z]. The characters
that match this pattern are defined by the current col-
lating sequence (see "ctab").
The "~" (tilde) character at the beginning of a file name
is used to see home directories. Standing alone, "~"
expands to your home directory as reflected in the value
of the home shell variable. When followed by a name that
consists of letters, digits, and "-" (dash) characters,
the shell searches for a user with that name and substi-
tutes their home directory. Thus, "~ken" might expand to
"/usr/ken" and "~ken/chmach" to "/usr/ken/chmach". If
the "~" character is followed by a character other than a
letter or "/", or appears anywhere except at the begin-
ning of a word, it is left undisturbed.
The pattern "a{b,c,d}e" is a shorthand for "abe ace
ade". The shell preserves the left-to-right order, with
results of matches being stored 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
if the home directory for "source" is "/usr/source".
Similarly:
../{memo,*box}
might expand to:
(Note that "memo" is not sorted with the results of
matching "*box".) As a special case, "{", "}", and "{}"
are passed undisturbed.
Alias Substitution
The shell maintains a list of aliases that the alias and
unalias built-in commands (page ) can establish, display,
and modify. After the shell scans the command line, it
divides it into distinct commands and checks the first
word of each command, left to right, to see if it has an
alias. If it does, the shell uses the history mechanism
available (see "History Substitution"), to replace the
text of the alias with the text of the command it stands
for. The words that result replace the command and argu-
ment list. If reference is not made to the history list,
then the argument list is left unchanged. Thus, if the
alias for the ls command is "ls -l", the shell replaces
the command "ls /usr" with "ls -l /usr", the argument
list here being undisturbed because there is not refer-
ence to the history list in aliased command. Similarly,
if the alias for lookup is:
grep !^ /etc/passwd
then the shell replaces "lookup bill" with:
grep bill /etc/passwd
Here, "!^" refers to the history list and the shell
replaces it with the first argument in the input line, in
this case "bill". Note that you can use special pattern-
matching characters in an alias. Thus the command:
alias lprint 'pr \!* >> print'
makes a command which formats its arguments to the line
printer. The ! is protected from the shell in the alias
so that it is not expanded until pr runs.
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. If the first word of
the next text is the same as the old, looping is pre-
vented by flagging it to prevent further aliasing. Other
loops are detected and cause an error.
Variable Substitution
The shell maintains a set of variables, each of which has
as its 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 var-
iable list, and words which comprise the value of this
variable are referred to in special ways.
You can change and display the values of variables with
the set and unset commands. Of the variables referred to
by the shell, a number are toggles (variables turn some-
thing on and off); the shell does not care what their
value is, only whether they are set or unset. For
instance, the verbose variable is a toggle which causes
command input to be echoed. The setting of this variable
results from the -v flag on the command line.
Other operations treat variables numerically. The @
command performs numeric calculations and the result is
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 multi-word
values are ignored.
After an input line is aliased and parsed, and before
each command is run, variable substitution is performed,
keyed by "$" characters. You can prevent this expansion
by preceding the "$" with a \, except within "" ""
(double quotation marks, where it always occurs, and
within "' '" (single quotation marks), where it never
occurs. Strings quoted by "' '" are interpreted later
(see "Command Substitution"), so "$" substitution does
not occur there until later, if at all. A "$" is passed
unchanged if it is followed by a blank, tab, or new-line
character.
Input/output redirections are recognized before variable
expansion and are expanded separately. Otherwise, the
command name and complete argument list expands together.
It is therefore 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 parameters.
Unless enclosed in "" "" or given the :q modifier, the
results of variable substitution may themselves eventu-
ally be command and file name substituted. Within pairs
of double quotation marks, a variable with a value that
consists of multiple words expands to a (portion of a)
single word, with the words of the variable's value sepa-
rated by blanks. When you apply the :q modifier to a
substitution, the variable expands to multiple words.
Each word is separated by a blank and quoted to prevent
later command or file name substitution.
The following notation allows you to introduce variable
values into the shell input. Except as noted, it is an
error to reference a variable that is not set.
$name
${name} Replaced by the words assigned to
name, each separated by a blank.
Braces insulate name from any fol-
lowing characters that would other-
wise be part of it. Shell variable
names start with a letter and
consist of up to 20 letters and
digits, including the "_" (under-
line) character. If name is not a
shell variable but is set in the
environment, then that value is
returned. The : modifiers and the
other forms given below are not
available in this case.
$name[selector]
${name[selector]} Used to select only some of the
words from the value of name. The
selector is subjected to "$" substi-
tution and may consist of a single
number, or two numbers separated by
a "-". The first word of a vari-
able's string 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 "*"
symbol selects all words. It is not
an error for a range to be empty 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[*]".
You can apply the modifiers :gh, :gt, :gr, :h, :r, :q,
and :x to the substitutions above. 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 changed with :
modifiers.
"$?"name
"${?"name} Substitutes the string 1 if name is
set; 0 if it is not set.
"$?"0 Substitutes 1 if the current input
file name is known; 0 if it is not
known.
"$$" Substitutes the (decimal) process
number of the (parent) shell.
"$<" Substitutes a line from the standard
input, without further interpreta-
tion. Use it to read from the key-
board in a shell procedure.
Predefined and Environmental 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 maintain their settings unless you
explicitly reset them.
The csh command copies the environment variables USER,
TERM, HOME, and PATH into the csh variables user, term,
home, and path, respectively. The values are copied back
into the environment whenever the normal shell variables
reset. It is not necessary to worry about the setting of
the path variable other than in the .cshrc file, since
csh subprocesses import the definition of path 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 parame-
ters are substituted.
cdpath Can be given a list of alternate directories
to be searched by the chdir commands to find
subdirectories.
cwd The full path name of the current directory.
echo Set when the -x command line flag is used;
when set, causes each command and its argu-
ments to echo just before it is run. For
nonbuilt-in commands, all expansions occur
before echoing. Built-in commands are
echoed before command and file name substi-
tution, since these substitutions are then
done selectively.
histchars Can be given a string value to change the
characters used in history substitution.
Use the first character of its value as the
history substitution character, this
replaces the default character "!". The
second character of its value replaces the
"^" (circumflex) character in quick substi-
tutions.
history Can be given a numeric value to control the
size of the history list. Any command that
is referenced in this many events is not
discarded. Very large values of history may
run the shell out of memory. Saves the last
command that ran on the history list,
regardless of whether history is set.
home Your home directory, initialized from the
environment. The file name expansion of ~
refers to this variable.
ignoreeof If set, the shell ignores an end-of-file
character from input devices that are work
stations. This prevents shells from acci-
dentally being killed when it reads an end-
of-file character (Ctrl-D).
mail The files where the shell checks for mail.
This is done after each command completion,
which results in a prompt if a specified
interval has elapsed. The shell displays
the message, ""You have new mail"" if the
file exists with an access time not greater
than its change time.
If the first word of the value of mail is
numeric, it specifies a different mail
checking interval (in seconds); the default
is 10 minutes. If you specify multiple mail
files, the shell displays the message, ""New
mail in file"", when there is mail in file.
noclobber If set, places restrictions on output redi-
rection to insure that files are not acci-
dentally destroyed, and that >> redirections
see existing files. (See "Redirecting Input
and Output")
noglob If set, inhibits file name expansion. This
is most useful in shell procedures that are
not dealing with file names, or after a list
of file names has been obtained and further
expansions are not desirable.
nonomatch If set, it is not an error for a file name
expansion to not match any existing files;
rather, the primitive pattern returns. It
is still an error for the primitive pattern
to be malformed.
notify If set, the shell notifies asynchronously of
changes in job status. The default presents
status changes just before displaying the
shell 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 var-
iable set, then only full path names run.
The usual search path is the current direc-
tory , /bin, and /usr/bin. For the super-
user, the default search path is /etc, /bin,
and /usr/bin. A shell which is given
neither the -c nor the -t flags normally
hashes 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 neces-
sary to give the rehash command (page ), or
the commands may not be found.
prompt The string which is displayed before each
command is read from an interactive work
station input. If a ! appears in the
string, it is replaced by the current even
number, unless a preceding \ is given. The
default prompt is %, # for the superuser.
savehist Given a numeric value to control the number
of entries of the history list that are
saved in ~/.history when you log out. Any
command which is referenced in this many
events is saved. During startup, the shell
reads ~/.history into the history list, ena-
bling history to be saved across logins.
Very large values of savehist slow down the
shell startup.
shell The file in which the shell resides. This
is used in forking shells to interpret files
which have execute bits set, but which are
not executable by the system (see
"Nonbuilt-in Command Execution"). This is
initialized to the (system-dependent) home
of the shell.
status The status returned by the last command. If
it ended abnormally, then 0200 is added to
the status. Built-in commands that fail
return exit status 1; all other built-in
commands set status 0.
time Controls automatic timing of commands. If
set, then any command that takes more than
this many CPU seconds cause a line giving
user, system, and real times and a utiliza-
tion percentage, that is the ratio of user-
plus-system-times to real time, displays
when it ends.
verbose Set by the -v command line flag, causes the
words of each command to display after
history substitution.
Redirecting Input and Output
You can redirect the standard input and standard output
of a command with the following syntax:
"<" name Opens file name (which is first variable,
command, and file name expanded) as the
standard input.
"<<" word Reads the shell input up to a line which is
the same as word. word is not subjected to
variable, file name, or command substitution,
and each input line is compared to word before
any substitutions are done on this input line.
Unless a quoting character (\, """, "'", or `)
appears in word, the shell performs variable
and command substitution on the intervening
lines, allowing \ to quote "$", \, and `.
Commands which are substituted have all
blanks, tabs, and new-line characters pre-
served, except for the final new-line char-
acter, 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 Uses the file name as standard output. If
the file does not exist, it is made. If the
file exists, it is truncated, its previous
contents being lost. If the noclobber shell
variable is set, the file must not exist or be
a character special file, or an error results.
This helps prevent accidental destruction of
files. In this case, use the "!" forms to
suppress this check. The forms involving "&"
route the diagnostic output into the specified
file as well as the standard output. name
expands in the same way as "<" input file
names.
">>" name
">>&" name
">>!" name
">>&!" name Uses file name as standard output like ">",
but places output at the end of the file. If
the noclobber shell variable is set, it is an
error for the file not to exist, unless one of
the "!" forms is given. Otherwise, it is
similar to ">".
A command receives the environment in which the shell was
invoked, as changed by the input/output parameters and
the presence of the command as a pipeline. Thus, unlike
some previous shells, commands that run from a file of
shell commands do not have any access to the text of the
commands by default. Rather, they receive the original
standard input of the shell. Use the "<<" mechanism to
present inline data. This lets shell command files func-
tion as components of pipelines and lets the shell block
read its input. Note that the default standard input for
a command run detached is not changed to be the empty
file /dev/null. Rather, the standard input remains as
the original standard input of the shell.
To redirect the diagnostics output through a pipe with
the standard output, use the form "|&" (vertical bar
ampersand) rather than just "|" (vertical bar).
Control Flow
The shell contains some commands that can be used to reg-
ulate the flow of control in command files (shell proce-
dures) and (in limited but useful ways) from work station
input. These commands all operate by forcing the shell
to reread or skip in its input and, because of the imple-
mentation, restrict the placement of some of the com-
mands.
The foreach, switch, and while statements, and the if-
then-else form of the if statement, require that the
major keywords appear in a single simple command on an
input line.
If the shell input is not searchable, the shell buffers
input whenever a loop is being read and searches the
internal buffer to do the rereading implied by the loop.
To the extent that this allows, backward gotos succeed on
inputs that you cannot search.
Built-in Commands
Built-in commands are run within the shell. If a
built-in command occurs as any component of a pipeline
except the last, it runs in a subshell.
Notes:
1. If you enter a command from csh at the prompt, the
system searches for a csh built-in command first. If
a built-in command does not exist, then the system
searches for an AIX command. Some csh built-in com-
mands and AIX commands have the same name. However,
these commands do not necessarily work the same way.
Check the appropriate command description for infor-
mation on how the command works.
2. If you run a shell procedure from csh and the first
characters of the shell procedure are
#!/shell_pathname, csh runs the shell specified in
the comment to process the procedure. Otherwise, csh
runs the standard shell (sh). If run by sh, csh
built-in commands are not recognized. To get the
system to run csh commands, the first line of the
procedure should be: "#!/bin/csh".
alias
alias name
alias name wordlist Displays all aliases (first
form). The second form displays
the alias for name. The final
form assigns the specified
wordlist as the alias of name.
wordlist is command and file name
substituted. name is not allowed
to be alias or unalias.
break Resumes running after the end of
the nearest enclosing foreach or
while. Runs the remaining com-
mands on the current line.
Multi-level breaks are therefore
possible by writing them all on
one line.
breaksw Breaks from a switch; resumes
after the endsw.
case label: Defines a label in a switch
statement, as discussed in the
following.
cd
cd name
chdir
chdir name Changes the current directory to
name. If no argument is given,
then changes to your home direc-
tory.
If name is not found as a subdi-
rectory of the current directory
and does not begin with "/",
"./", or "../", then each compo-
nent of the cdpath shell variable
is checked to see if it has a
subdirectory name. Finally, if
all else fails, but name is a
shell variable with a value that
begins with "/", then this is
tried to see if it is a direc-
tory.
continue Continues execution of the
nearest enclosing while or
foreach. The rest of the com-
mands on the current line run.
default: Labels the default case in a
switch statement. The default
should come after all case
labels.
dirs Displays the directory stack, the
top of the stack is at the left,
the first directory in the stack
being the current directory.
echo string
echo -n string . . . Writes the listed strings to the
shell's standard output, sepa-
rated by spaces and ending with a
new-line character unless you
specify the -n flag.
else
end
endif
endsw See the description of the
foreach, if, switch, and while
statements.
eval arg . . . Reads arg as input to the shell
and runs the resulting command(s)
in the context of the current
shell. Use this to run commands
generated as the result of
command or variable substitution,
since parsing occurs before these
substitutions.
exec cmd Runs the specified command in
place of the current shell.
exit
exit (expr) Exits the shell with either the
value of the status shell vari-
able (first form) or with the
value of the specified expression
(second form).
foreach name (list)
. . .
end Successively sets name to each
member of list and runs the
sequence of commands between the
foreach and the matching end.
Both foreach and end must appear
alone on separate lines.
Use the continue statement to
continue the loop and the break
statement to end the loop prema-
turely. When this command is
read from the work station, the
loop is read once, prompts with
"?" before any statement in the
loop runs. If a mistake is made
in entering a loop, it can be
corrected before you run the
loop. Commands within loops,
prompted for by "?", are not
placed in the history list.
glob list Functions like echo, but does not
recognize backslash (\) escapes,
and delimits words by null char-
acters in the output. Useful for
programs that wish to use the
shell to file name expand a list
of words.
goto word Continues to run after the line
specified by word The specified
word is file-name and command
expanded to yield a string of the
form label. The shell rewinds
its input as much as possible and
searches for a line of the form
label:, possibly preceded by
blanks or tabs.
history
history num
history -r num
history -h num Displays the history event list.
If you specify a number, only the
n most recent events are dis-
played. The -r flag reverses the
order of display to the most
recent first rather than the
oldest first. The -h flag causes
the history list to be displayed
without leading numbers. Use
this to produce files suitable
for used with the -h flag of the
source command.
if (expr) cmd Runs the single command (with
arguments) if the specified
expression evaluates true. Vari-
able substitution on cmd happens
early, at the same time it does
for the rest of the if statement.
cmd must be a simple command, not
a pipeline, command list, or
parenthesized command list.
Note: Input and output redi-
rection occurs even if expr is
false (and the command is not
executed).
if (expr) then
. . .
else if (expr2) then
. . .
else
. . .
endif If expr is true, runs the com-
mands that follow the first then;
else if expr2 is true, runs the
commands that follow the second
then; else runs the commands that
follow the second else. Any
number of else-if pairs are pos-
sible; only one endif is needed.
The else part 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
jobs -l Lists the active jobs. With the
-l flag, lists process-IDs in
addition to the job number and
process-ID.
kill %job
kill -signal %job . . .
kill pid
kill -signal pid . . .
kill -l Sends to the jobs or process that
you specify either the TERM (ter-
minate) signal or signal.
Specify signals either by number
or by names (as given in
/usr/include/signal.h, stripped
of the SIG prefix). Signal names
are listed by kill -l.
limit
limit resource
limit resource max-use Limits the usage by the current
process and each process it
creates to not individually
exceed max-use on the specified
resource. If a max-use is not
given, the current limit dis-
plays; if a resource is not
given, all limitations are given.
Controllable resources are
limited to filesize, stacksize,
and datasize. You can specify
max-use as a (floating-point or
integer) number followed by a
scale factor: k or kilobytes
(1024 bytes), m or megabytes, or
b or blocks (the units used by
the ulimit system call). For
both resource names and scale
factors, unambiguous prefixes of
the names suffice. The filesize
may be lowered by an instance of
csh, but may only be raised by an
instance whose effective user-ID
is "root". (See the ulimit
system call in AIX Operating
System Technical Reference.)
login Ends a login shell, and replaces
it with an instance of
/bin/login. This is one way to
log out (included for compat-
ibility with the sh command).
logout Ends a login shell. Especially
useful if ignoreeof is set.
newgrp Executes the newgrp command in
the current shell process. See
"newgrp" for a discussion of
command options.
nice
nice +num
nice cmd
nice +num cmd Sets the priority of commands run
in this shell to 24 (first form).
The second form sets the priority
to the specified number. The
final two forms run the specified
command at priority 24 and the
specified number, respectively.
If you are have superuser
authority you can specify nice
with a negative number. The
command always runs in a sub-
shell, and the restrictions
placed on commands in simple if
statements apply.
nohup
nohup cmd Causes hangups to be ignored for
the remainder of the procedure
(first form). The second form
causes the specified command to
be run with hangups ignored. To
run a pipeline or list of com-
mands with this form, put the
pipeline or list in a shell pro-
cedure, give the procedure
execute permission, and use the
shell procedure as the cmd. All
processes run in the background
with "&" are effectively pro-
tected from being sent a hangup
signal when you log out, but will
still be subject to explicitly
sent hangups unless nohup is
used.
notify
notify %job . . . Causes the shell to notify you
asynchronously when the status of
the current or specified jobs
changes. Normally, notification
is presented just before the
shell prompt. This is automatic
if the notify shell variable is
set.
onintr
onintr -
onintr label Controls the action of the shell
on interrupts. The first form
restores the default action of
the shell on interrupts, which is
to end shell procedures or to
return to the work station
command input level. The second
form causes all interrupts to be
ignored. The third form causes
the shell to run a goto label
when it receives an interrupt or
a child process ends due to an
interruption. 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
popd +n Pops the directory stack, returns
to the new top directory. With a
+n, discards the nth entry in the
stack. The elements of the
directory stack are numbered from
the top starting at 0.
pushd
pushd name
pushd +n With no arguments, exchanges the
top two elements of the directory
stack. With name, changes to the
new directory and pushes the old
current directory (as given in
the cwd shell variable) onto the
directory stack. With a numeric
argument, rotates the nth argu-
ment 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 shell variable to be
recomputed. This is needed if
new commands are added to direc-
tories in path while you are
logged in. This should only be
necessary if commands are added
to one of the user's own directo-
ries, or if someone changes the
contents of one of the system
directories.
repeat count cmd Runs the specified command, which
is subject to the same
restrictions as the if statement,
count times.
Note: I/O redirections occur
exactly once, even if count is 0.
set
set name
set name=word
set name"["index"]"=word
set name=(list) Shows the value of all shell var-
iables (first form). Variables
that have more than a single word
as their value are displayed as a
parenthesized word list. The
second form sets name to the null
string. The third 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 list. In
all cases, the value is command
and file name expanded. These
arguments may be repeated to set
multiple values in a single set
command. However, variable
expansion happens for all argu-
ments before any setting occurs.
setenv name value Sets the value of environment
variable name to be 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; there is no need to use
setenv for these.
If you modify the environment
variables NLFILE or NLCTAB, the
current international character
support environment and collating
sequence are changed as specified
for subsequent commands executed
from the shell.
shift
shift variable Shifts the members of argv to the
left. It is an error for argv
not to be set or to have less
than one word as its value. The
second form does the same func-
tion on the specified variable.
source name
source -h name Reads commands from name. You
can nest the source commands.
However, if they are nested too
deeply, the shell may run out of
file descriptors. An error in a
source command at any level ends
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 running.
switch (string)
case str1:
. . .
breaksw
default:
. . .
breaksw
endsw Successively matches each case
label against string. The string
is command and file-name expanded
first. Use the pattern-matching
characters "*", "?", and "[" . .
. "]" 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
breaksw command causes execution
to continue after the endsw.
Otherwise, control may fall
through case labels and the
default labels, as in C. If no
label matches and there is no
default, execution continues
after the endsw.
time
time cmd With no argument, displays a
summary of time used by this
shell and its children. If argu-
ments are given, the specified
command is timed, and a time
summary as described under the
time shell variable is displayed.
If necessary, an extra shell is
created to display the time sta-
tistic when the command com-
pletes.
umask
umask value Displays the file creation mask
(first form) or sets it to the
specified value (second form).
The mask is given as an octal
value. Common values for the
mask are 002, giving all access
to owner and group and read and
execute access to others, or 022,
giving all access to the owner
and all access except write
access for users in the group or
others.
unalias pattern Discards all aliases with names
that match pattern. Thus, all
aliases are removed by unalias *.
It is not an error for nothing to
be unaliased.
unhash Disables the use of the internal
hash table to locate running pro-
grams.
unlimit
unlimit resource Removes the limitation on
resource. If you do not specify
resource, then all resource limi-
tations are removed. The only
removable limitation is that on
filesize, and only the superuser
can remove it.
unset pattern Removes all variables with names
that match the pattern. Use
unset * to remove all variables.
It is not an error for nothing to
be unset.
unsetenv pattern Removes all variables from the
environment whose names match the
specified pattern. (See the
setenv built-in command on page
.)
wait Waits for all background jobs.
If the shell is interactive, an
INTERRUPT (Alt-Pause) can disrupt
the wait, when the shell displays
the names and job numbers of all
jobs known to be outstanding.
while (expr)
. . .
end Evaluates the commands between
the while and the matching end
while expr evaluates nonzero.
You can use break to end and con-
tinue to continue the loop prema-
turely. The while and end must
appear alone on their input
lines. If the input is a work
station, prompts occur the first
time through the loop, as for the
foreach statement.
@
@ name = expr
@ name"["index"]" = expr Displays the values of all the
shell variables (first form).
The second form sets the speci-
fied name to the value of expr.
If the expression contains "<",
">", "&", or "|", then at least
this part of the expression must
be placed within parentheses.
The third form assigns the value
of expr to the indexth argument
of name. Both name and its
indexth component must already
exist.
C operators, such as "*=" and
+"=" are available. The space
separating name from the assign-
ment operator is optional.
Spaces are, however, required in
separating components of expr,
which would otherwise be single
words. Special postfix ++ and
"--" operators increase and
decrease name.
Expressions
The @ built-in command and the exit, if, and while state-
ments accept expressions which include operators similar
to those of C, with the same precedence. The following
operators are available:
* / %
+ -
<< >>
<= >= >
== != =~ !~
In the preceding list, operators of equal precedence
appear on the same line, below those lines containing
operators (if any) that have greater precedence and above
those lines containing operators having lesser preced-
ence. The "==", "!=", "="~, and "!~" operators compare
their arguments as strings; all others operate on
numbers. The "=~" and "!~" operators are similar to "!="
and "==", except that the right-most side is a pattern
against which the left-hand operand is matched. This
reduces the need for use of the switch statement in shell
procedures when all that is really needed is pattern
matching.
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 now two components
of an expression can appear in the same word; except when
next to components of expressions which are syntactically
significant to the parser ("&"" |"" <" ">" "(" ")"),
expression components 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:
r Read access
w Write access
x Execute access
e Existence
o Ownership
z Zero size
f Plain file
d Directory
The specified name is command and file name expanded and
then tested to see if it has the specified relationship
to the real user. If the file does not exist or is inac-
cessible, then all inquiries return false, that is, 0.
Command runs succeed, returning true (1), if the command
exits with status 0, otherwise they fail, returning false
(0). If more detailed status information is required,
run the command outside an expression and the examine
status shell variable.
Nonbuilt-in Command Execution
When a command to run is found not to be a built-in
command, the shell attempts to run the command with
execve. (See the exec system call in AIX Operating System
Technical Reference.) Each word in the path shell vari-
able names a directory from which the shell attempts to
run 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 it only tries an exec in a
directory if there is a possibility that the command
resides there. If this mechanism has been turned off
with unhash, or if the shell is given a -c or -t (and in
any case for each directory component of path that 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 run.
Parenthesized commands always run in a subshell. Thus,
"(cd ; pwd) ; pwd" displays the home directory without
changing the current directory location, whereas "cd ;
pwd" changes the current directory location to 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 exe-
cutable binary to the system, then it is assumed to be a
file containing shell commands and a new shell runs to
read it.
If there is an alias for shell, then the words of the
alias will be prefixed to the argument list to form the
shell command. The first word of the alias should be the
full path name of the shell. Note that this is a
special, late-occurring case of alias substitution and
only allows words to be prefixed to the argument list
without modification.
SIGNAL HANDLING: The shell normally ignores quit
signals. Jobs running detached are immune to signals
generated from the keyboard (Interrupt, Quit, and
Hangup). Other signals have the values the shell inher-
ited from its parent. You can control the shell's han-
dling of interrupt and terminate signals in shell
procedures with 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
.logout file.
Limitations
The following are csh limitations:
o Words can be no longer than 1024 characters.
o Argument lists are limited to 5120 characters.
o The number of arguments to a command that involves
file name expansion is limited to 1/6th the number of
characters allowed in an argument list.
o Command substitutions can substitute no more charac-
ters than are allowed in an argument list.
o To detect looping, the shell restricts the number of
alias substitutions on a single line to 20.
FLAGS
If the first argument to the shell is - (minus), this is
a login shell. The flags are interpreted as follows:
-c Reads commands from the (single) following argu-
ment, which must be present. Any remaining argu-
ments are placed in argv.
-e Exits if any invoked command ends abnormally or
yields a nonzero exit status.
-f Starts without searching for or running commands
from the .cshrc file in the your home directory.
-i Prompts for its top-level input (an interactive
shell), even if input does not appear to be coming
from a work station. Shells are interactive
without this flag if their input and output are
attached to work stations.
-n Parses commands but does not run them. This aids
in syntactic checking of shell procedures.
-s Takes command input from the standard input.
-t Reads and processes a single line of input. You
can use a \ to escape the new-line character at the
end of the current line to continue onto another
line.
-v Sets the verbose shell variable, with the effect
that command input is echoed after history substi-
tution.
-V Sets the verbose shell variable even before .cshrc
runs.
-x Sets the echo shell variable, so that commands are
echoed immediately before they run.
-X Sets the echo shell variable even before .cshrc
runs.
After processing of flag arguments, if arguments remain
but none of the -c, -i, -s, or -t flags were given, the
first parameter is taken as the name of a file of com-
mands (shell procedure). The system opens this file and
saves its name for possible resubstitution by $0. If the
first characters of the shell procedure are
#!/shell_pathname, csh runs the specified shell to
process the procedure. Otherwise, csh runs the standard
shell (sh). Remaining parameters initialize the argv
variable. For more information on the #!/shell_pathname
comment, see the exec system call in AIX Operating System
Technical Reference.
FILES
$HOME/.cshrc Read at beginning of execution by each
shell.
$HOME/.login Read by login shell, after .cshrc at
login.
$HOME/.logout Read by login shell, at logout.
/bin/sh Standard shell.
/tmp/sh* Temporary file for <<.
/etc/passwd Source of home directories for ~name.
RELATED INFORMATION
The following commands: "cd," "make," "pr," and "sh."
The access, exec, fork, pipe, umask, and wait system
calls, the a.out and environ files, and the environment
miscellaneous facility in AIX Operating System Technical
Reference.
"Overview of International Character Support" in Managing
the AIX Operating System.