csh - C shell command interpreter
csh [-bcefinstvVxX] [argument...]
The csh command invokes the C shell and interprets C shell
commands.
Forces a break from option processing, causing any further
shell arguments to be treated as nonoption arguments.
This can be used to pass options to a shell script without
confusion or possible subterfuge. The shell cannot run a
set-user-ID script without this option. Reads commands
from the following single argument, which must be present.
Any remaining arguments are placed in argv. Causes the
shell to exit if any invoked command terminates abnormally
or yields a nonzero exit status. Causes the shell to
start faster, because it neither searches for nor executes
the file in the invoker's home directory. Causes the
shell to be interactive, even if the input does not come
from a terminal. Shells are always interactive when
invoked from a terminal. Parses commands, but does not
execute them. This aids in syntactic checking of shell
scripts. Takes command input from the standard input.
Reads and executes a single line of input. You can use a \
(backslash) to escape the newline character at the end of
the current line to continue onto another line. Sets the
verbose shell variable, with the effect that command input
is echoed to the standard output after history substitution.
Sets the verbose shell variable, even before is
executed. Sets the echo shell variable, so that commands
are echoed to the standard error after all substitutions
and immediately before execution. Sets the echo shell
variable, even before is executed.
After processing of option arguments, if arguments remain
but none of the -c, -i, -s, or -t options was given, the
first argument is taken as the name of a file of commands
to be executed (that is, a shell script). The shell opens
this file, and saves its name for possible resubstitution
by $0. If the first characters of the shell script are
#!shell_pathname or #csh, csh runs the specified shell to
process the script. Otherwise, csh runs. Remaining parameters
initialize the argv variable.
The C shell is an interactive command interpreter and a
command programming language that uses a syntax similar to
the C programming language. The shell carries out commands
either from a file (called a shell script or procedure)
or interactively from a terminal keyboard.
When you run csh, it begins by executing commands from the
file in your home directory, if it exists. If the shell
is invoked with a name that starts with -, as when started
by login, the shell runs as a login shell. If csh runs as
a login shell, it executes commands from the system-wide
login file /etc/csh.login, if that file exists, and then
commands from your $home/.cshrc file and your $home/.login
file, in that order. (If argument zero ($0) to the shell
is a - (dash), then the shell is a login shell.) Your
system administrator can create /etc/csh.login to provide
a standardized environment for all users, but you can
include commands in $home/.cshrc or $home/.login to override
settings and assignments made by /etc/csh.login.
At log in, the $home shell variable and the $HOME environment
variable both refer to your home directory. If you
subsequently change $home to some other value, you will
encounter problems because the shell will not be able to
find files it uses, such as and
In the normal case, the shell begins reading commands from
the terminal, prompting with % (percent sign) or # (number
sign) for the superuser. Processing of arguments and the
use of the shell to process files containing command
scripts is 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. Each command in the current line is
executed.
When a login shell terminates, it executes commands from
the file in your home directory.
Shell Features [Toc] [Back]
Job control and status reporting File name completion History
substitution Command aliasing Variable substitution
Command substitution File name substitution Input/output
redirection and control flow Built-in commands
Lexical Structure [Toc] [Back]
A simple command is a sequence of words separated by
spaces or tabs. The shell splits input lines into words
at spaces and tabs with the following exceptions: The
characters &, |, ;, <, >, (, ), and # form separate words.
If doubled in &&, ||, <<, or >>, these pairs form single
words. Preceding parser metacharacters with a \ (backslash)
prevents the shell from interpreting them as special
characters. A newline preceded by a \ (backslash) is
equivalent to a space. Strings enclosed in " " (double
quotes), ` ` (grave accents), or ' ' (single quotes) form
parts of a word; metacharacters in these strings, including
spaces and tabs, do not form separate words. For more
information, see the section Quoting with Single and Double
Quotes. Within pairs of ' or " characters, you can
include the newline character by preceding it with a \
(backslash). When the shell is not reading input from a
terminal, it treats any word that begins with a # (number
sign) character as a comment and ignores that word and all
characters following up to the next newline character. The
# character loses its special meaning when it is quoted
(preceded) by a \ (backslash) or when the string is
enclosed in quotes using `, ', or ".
When the shell is reading input from a terminal
without the c option, the # character is not
treated specially. However, when reading input
from a terminal with the c option, the shell treats
a # character as the start of a comment and ignores
subsequent text up to the next newline unless the #
is quoted with a \ (backslash) or the string is
enclosed in quotes using `, ', or ".
Shell Commands [Toc] [Back]
A simple command is a sequence of words, the first of
which (numbered 0) specifies the command to be executed.
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
script. In this case, it starts another shell to read the
file and execute the commands included in it. (See the
section Nonbuilt-In Command Execution for information
about using the $shell variable to determine which shell
is executed.)
A pipeline is a sequence of one or more commands separated
by either the | (vertical bar) or |& (vertical bar and
ampersand) characters. With |, the standard output of the
preceding command is redirected to the standard input of
the command that follows. With |&, both the standard error
and the standard output are redirected. Note that you cannot
pipe to a built-in command and an attempt to do so
generates an error message. A list is a sequence of
pipelines separated by a ; (semicolon), & (ampersand), &&
(two ampersands), or || (two vertical bars) and optionally
ended by a ; (semicolon) or an & (ampersand). These separators
and terminators have the following effects: Causes
sequential execution of the preceding pipeline (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 0 (zero) exit value. Causes the list following
it to be executed only if the preceding pipeline returns a
nonzero exit value.
The ; (semicolon) and & (ampersand) separators have equal
precedence, as do && and ||. The single-character separators
have lower precedence than the double-character separators.
A newline character without quotes following a
pipeline functions the same as a ; (semicolon). A
pipeline or sequence can be enclosed in () (parentheses)
to form a simple command.
Job Control [Toc] [Back]
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 terminating
the command with &, the shell displays a line that looks
like this: [1] 1234
This line indicates that the job number is 1 and that the
job is composed of one process with the process ID of
1234. Use the built-in jobs command to see the table of
current jobs.
If you are running a job and want to do something else,
you can enter the Suspend key sequence (normally <Ctrl-z>)
which sends a stop signal to the current job. The shell
then normally indicates that the job has been stopped and
it prints another prompt. You can then manipulate the
state of this job, putting it in the background with the
bg command, or run some other commands and then eventually
bring the job back into the foreground with the foreground
command fg. The job suspension takes effect immediately,
and is similar to the Interrupt key sequence in that
pending output and unread input are discarded. A special
key sequence, <Ctrl-y>, does not generate a stop signal
until a program attempts to read it. (See the read() system
call for more information.) This key sequence can
usefully be typed ahead when you have prepared some commands
for a job that you want to stop after it has read
them.
Multiple interactive loop based commands can be started
and suspended. These suspended commands can be restarted
in any arbitrary order. When a suspended job is
restarted, it must be run in the foreground rather than in
the background. If an attempt is made to restart it in
the background, the shell restarts only the command that
was suspended and terminates once the job completes without
continuing with the rest of the loop.
A job being run in the background stops if it tries to
read from the terminal. Background jobs are normally
allowed to produce output, but this can be disabled by
entering the stty tostop command. If you set this terminal
option, background jobs stop when they try to produce
output like they do when they try to read input.
There are several ways to refer to jobs in the shell. Use
the % (percent sign) with the fg and bg built-in commands
to control the job. This name can be either the job number
or a prefix of the string that started the job, if
this name is unique. (% can be used to refer to both
background and foreground jobs.)
For example, if a make process is running as job number 1,
you can refer to it as %1. You can also refer to it as
%make, if there is only one job with a name that begins
with the string make. You can also use the following
characters to specify a job whose name contains string, if
there is only one such job: %?string
Just naming a job brings it to the foreground, so %1 is a
synonym for fg %1, bringing job 1 back into the foreground.
Similarly, entering %1 & resumes job 1 in the
background. Thus, %ex normally restarts a stopped ex job
if there was only one stopped job whose name began with
the string ex.
The shell maintains a notion of the current and previous
jobs. In output produced by the built-in command jobs, the
current job is marked with a + (plus sign) and the previous
job with a - (dash). The abbreviation %+ refers to the
current job and %- refers to the previous job. For close
analogy with the syntax of the history mechanism
(described later), %% is also a synonym for the current
job.
Status Reporting [Toc] [Back]
The shell tracks the state of each job and reports whenever
a job finishes or becomes blocked. The shell prints
the status information just before it prints the prompt to
avoid disturbing the appearance of the terminal screen.
If, however, you set the notify shell variable, the shell
notifies you immediately of changes of status in background
jobs. There is also a notify shell command that
marks a single process so that its status changes are
immediately reported. By default notify marks the current
process. Simply enter notify after starting a background
job to mark the job.
When you try to leave the shell while jobs are stopped,
you are warned that you have stopped jobs. You can use
the built-in jobs command to see what they are. If you
then immediately exit the shell, or use jobs and then
exit, the shell does not warn you a second time, and the
suspended jobs are terminated.
File Name Completion [Toc] [Back]
The file name completion feature is enabled by setting the
shell variable filec. The csh interactively completes
file names and user names from unique prefixes when they
are input from the terminal followed by the escape character
(the <ESC> key or <Ctrl-[>)). For example, assume the
current directory looks like this:
DSC.OLD bench chaos cmd dev mail xmpl.c xmpl.out
DSC.NEW bin class cmtest lib mbox xmpl.o
The input is as follows: % vi ch<ESC>
The csh completes the prefix ch to the only matching file
name chaos: vi chaos
However, given the following command line: vi D<ESC>
csh only expands the input as follows: vi DSC.
The csh sounds the terminal bell to indicate that the
expansion is incomplete, because two file names match the
prefix D.
If a partial file name is followed by the End-of-File
character (shown here as <Ctrl-d>), then instead of completing
the name, csh lists all file names matching the
prefix. For example, the following input causes all files
beginning with D to be listed: vi D<Ctrl-d>
DSC.NEW DSC.OLD
The input line is then echoed again for you to complete.
The same system of <ESC> and <EOF> can also be used to
expand partial user names, if the word to be completed (or
listed) begins with ~ (tilde). For example, entering the
following command line: cd ~ro<ESC>
can produce the following 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 particular 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
fignore is set by the following command: % set fignore =
(.o .out)
typing % vi x<ESC>
results 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,
then they are not ignored. In addition, fignore
does not affect the listing of file names by <Ctrl-d>.
All files are listed regardless of their suffixes.
History Substitution [Toc] [Back]
History substitution places 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. History substitutions
begin with the ! (exclamation point) character and can
begin anywhere on the command line, provided they do not
nest (in other words, a history substitution cannot contain
another history substitution). You can precede the !
with a \ (backslash) to prevent the exclamation point's
special meaning. In addition, if you place an ! (exclamation
point) before a space, tab, newline, = (equal
sign), or ( (left parenthesis), the exclamation point is
passed to the parser unchanged. (History substitutions
also occur when you begin an input line with a ^ (circumflex).
This special abbreviation is described later.) The
shell echoes any input line containing history substitutions
before it executes that command line.
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 into the input stream.
The history shell variable controls the size of the history
list. You must set the history shell variable either
in the file or on the command line with the built-in set
command. The previous command is always retained, however,
regardless of the value of history. Commands in the
history list are numbered sequentially, starting from 1.
The built-in history command produces output of the type:
9 write michael 10 ex 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 displayed
as part of your system prompt by placing an !
(exclamation point) in the prompt string assigned to the
prompt variable.
A full history reference contains an event specification,
a word designator, and one or more modifiers in the following
general format:
event[:]word:modifier[:modifier]...
Note that only one word can be modified. A string that
contains spaces is not allowed.
In the previous sample of history command output, the current
event number is 13. Using this example, the following
refer to previous events: Refers to event number 10.
Refers to event number 11 (the current event minus 2).
Refers to a command word beginning with d (in this case,
event number 12). Refers to a command word that contains
the string mic (in this case, event number 9).
These forms, without further modification, simply reintroduce
the words of the specified events, each separated by
a single space. 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 specification
by a : (colon) and one of the following word designators.
The words of an input line are numbered sequentially,
starting from 0 (zero), with the first (usually
command) word being 0 (zero), the second word (first argument)
being 1, and so on. The basic word designators are
as follows: First word (command). The nth argument, where
n > 0, for example, !!:3 recalls the third word of the
previous command and !:2 recalls to the second word of the
current command. !#:n is the same as !:n and recalls the
nth word of the current command. First word (word 1).
Last word. Word matched by (the immediately preceding)
?string? history search. Range of words from x through y.
Words 0-y. The second through the last words, or nothing
if only one word in event. Words x- $ Like x*, but omits
the last word ($).
You can omit the : (colon) separating the event specification
from the word designator if the word designator
begins with a ^, $, *, -, or %. You can also place a
sequence of modifiers, each preceded by a : (colon), after
the optional word designator. The following modifiers are
defined: Repeats the previous substitution. Removes all
but the trailing extension Applies the change globally,
prefixing another modifier, for example g&. Removes a
trailing path name extension, leaving the head. Prints
the new command, but does not execute it. Quotes the substituted
words, thus preventing further substitutions.
Removes a trailing component, leaving the root name. Substitutes
r for l. It is an error for no word to be applicable.
Removes all leading path name components, leaving
the tail. Like q, but breaks into words at space, tab or
newline.
Unless the modifier is preceded by a g, the change is
applied only to the first modifiable word.
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 spaces. Normally, a /
(slash) delimits the word (l) and its replacement (r).
However, you can use any character as the delimiter.
Thus, in the following example the = character becomes the
delimiter, allowing you to include the / in your word:
s=/usr/myfile=/usr/yourfile=
If you include an & (ampersand) in the replacement (r), it
is replaced by the text from the left-hand side (l). A
null l side is replaced by either the last l string or by
the last string used in the contextual scan !?string?. You
can omit the trailing delimiter (/) if a newline character
follows immediately.
A history reference can be given without an event specification.
For example, !$ refers to the last argument of
the previous command. If a history reference without an
event specification is not the first history reference on
the line, it refers to the previous history reference on
the line and not to a previous event. For example, in
!?foo?^ !$, !?foo?^ gives the first argument of the command
matching ?foo?, and the !$ gives the last argument of
that same command, not the last argument of the previous
command (as it would if it were on a line by itself).
A special abbreviation of a history reference occurs when
the first nonspace character of an input line is a ^ (circumflex).
This is equivalent to !:s^, providing a convenient
shorthand for substitutions on the text of the previous
line. Thus, ^lb^lib corrects the spelling of lib in
the previous command. Finally, a history substitution can
be enclosed in { } (braces) to insulate it from the characters
that follow. Thus, after ls -ld ~paul you might
specify !{l}a to do ls -ld ~paula, or !la to rerun a command
starting with la.
Command Line Editing (cmdedit) [Toc] [Back]
If you are using a video display terminal or a workstation
terminal emulator, csh allows you to recall and edit commands
as if you were using an editor; this capability is
in addition to the history mechanism. This version of the
C shell provides intra-command line editing that includes
features such as a kill buffer, multiline named keyboard
macros which can be automatically saved and restored, convenient
access to the history list, and user settable key
bindings. A summary of the currently available functions
is provided below. In most cases, the functionality is
apparent from the names of the routines in the list.
The shell's editing mode is determined by the value of the
shell editmode variable which users should set to emacs or
vi in their files. If editmode is not set, then the shell
will run in "dumb" mode. It is possible to set the mode
after the shell starts up; so if you find yourself in
"dumb" mode, you can alter the situation without having to
log out and log in again. Setting the editmode variable
has two important side effects: (1) it causes the key
bindings to be reevaluated, and (2) it sets the EDITMODE
environment variable. The latter has no effect within the
shell; so users should not set the environment variable
directly in hopes of altering the editing mode.
Terminal control capabilities are extracted from the
user's termcap file (usually /etc/termcap), using the
value of the shell variable term, not the environment
variable TERM, as the terminal type. If term is undefined,
unknown, or if the associated termcap definition is
inadequate, a warning will be displayed and most, or all,
of the editing features of the shell will be disabled. It
is the user's responsibility to make sure that term is set
to an appropriate value before the shell editor is initialized.
Usually this should be done in the file. If
editing is disabled because term is not properly set when
the shell starts up, simply setting term to the proper
value will normally cause the shell editor to be reenabled.
NB: Setting the shell variable term causes the
environment variable TERM to be set to the same value. For
information on controlling the bell, see the ERRORS section.
There is a bind-to-key command in this shell, which allows
the functions listed in the table on bindings below, and
also user defined keyboard macros, to be bound to keys.
The form of the command is bind-to-key function key ...
where function is one of the function names from the list
or else the single character name of a keyboard macro and
where key is a quoted string designating a key sequence.
Control characters in the key designation should not be
entered literally, but should be indicated by the prefix
"\^", e.g. "\^X". Similarly, escape is indicated by
"\e". A literal backslash is "\\". Escape and control-X
are the only legitimate "prefix" characters. For vi mode,
bindings prefixed with control-X are for insert mode.
Otherwise, the bindings are in effect only in command
mode. The following mnemonics should be used:
\^? delete (rubout)
\^c control character
\n line feed (new line)
\b back space
\t horizontal tab
\v vertical tab
\f form feed
\r carriage return
\e escape
\nnn character code in octal
Since the shell converts returns to newlines, it is probably
unwise to alter the binding of newline. A common binding
is to bind KillRegion to Ctrl/U, which would be accomplished
using the following command: bind-to-key KillRegion
"\^U"
During editor initialization the shell will read a file
named in the user's home directory. If you regularly want
certain non-default key bindings to be effective, put the
appropriate bind-to-key commands in your ~/.bindings file.
NB: Do not place the bind-to-key commands in your ~/.cshrc
or ~/.login file; they must be in the ~/.bindings file.
Invocation of the history mechanism with "!" either causes
the matched command to be inserted on the command line for
editing before execution or immediately executes the command.
This is controlled by the shell variable edithist,
which is automatically set, when the shell variable editmode
is set, thereby allowing editing of previous commands
invoked by the history mechanism. This feature may be
turned off with the command "unset edithist", which may be
placed in the user's file.
The following table shows the current functions and
default key bindings:
Emacs Function Name Remark
^B Backspace
ESC-b BackwardWord
^A BeginningOfLine
^L ClearScreen
DefaultBinding
ESC-n DefineNamedMacro name macro
^D DeleteCurrentChar
^H DeletePreviousChar
ESC-d DeleteWord after cursor
EndOfFile exit shell
^E EndOfLine
EraseLine kills whole line
ESC-h EraseWord before cursor
ExecuteMacro
ESC-e ExecuteNamedMacro
ESC-x ExecuteNamedMacro
^X-e ExecuteUnNamedMacro
ESC-ESC FilenameExpansion
ESC-l FilenameList
^F ForwardChar
ESC-f ForwardWord
GnuTransposeChars like gnu-emacs
IncrementalSearchForward
IncrementalSearchReverse
InsertChar self insert
^V InsertLiteralChar
^W KillRegion to kill buffer
^K KillToEOL to kill buffer
^X^R LoadMacroFile
^N NextHistEntry wraps around
^P PreviousHistEntry wraps around
^R Redisplay redraws line
^U Repetition greater than 0
^M,^J Return
^X^S SaveMacroFile
^@ SetMark default mark at
BOL
SearchReverse look for next char
SearchForward look for next char
^Q StartFlow (see FLOW CONTROL)
^X-( StartRemembering begin a macro
^S StopFlow (see FLOW CONTROL)
^X-) StopRemembering end a macro
^I Tab inserts 8 spaces
^T TransposeChars before cursor
WipeLine kill line without
saving
^Y YankKillBuffer no kill ring
Vi Function Name Remark
A AppendToEOL can't use with
bind-to-key
^H BackSpace
h BackSpace
B BackwardWord
b BackwardWord
0 BeginningOfLine
^ BeginningOfLine
s ChangeChar can't use with
bind-to-key
c ChangeFollowingObject can't use with
bind-to-key
C ChangeToEOL can't use with
bind-to-key
S ChangeWholeLine can't use with
bind-to-key
x DeleteCurrentChar
d DeleteFollowingObject can't use with
bind-to-key
X DeletePreviousChar can't use with
bind-to-key
$ EndOfLine
ESC FilenameExpansion
^D FilenameListOrEof
l ForwardChar
SPACE ForwardChar
w ForwardWord
W ForwardWord
e ForwardWord
I InsertAtBOL can't use with
bind-to-key
D KillToEOL
@ ExecuteNamedMacro
+ NextHistEntry
j NextHistEntry
^N NextHistEntry
- PreviousHistEntry
k PreviousHistEntry
^P PreviousHistEntry
^L Redisplay
^R Redisplay
z Redisplay
1-9 Repetition
r ReplaceChar can't use with
bind-to-key
LINEFEED Return
RETURN Return
/ IncrementalSearchForward
? IncrementalSearchReverse
f SearchForward
F SearchReverse
m SetMark
a EnterViAppend can't use with
bind-to-key
i EnterViInsert can't use with
bind-to-key
p ViYankKillBuffer can't use with
bind-to-key
P ViYankKillBuffer can't use with
bind-to-key
Vi insert mode
^H DeletePreviousChar
EraseChar DeletePreviousChar
^W EraseWord
ESC ExitViInsert can't use with
bind-to-key
^D FilenameListOrEof
^Q InsertLiteralChar
^V InsertLiteralChar
^U KillRegion
^N NextHistEntry
^P PreviousHistEntry
^L Redisplay
^R Redisplay
LINEFEED Return
RETURN Return
TAB Tab
Users may change the bindings of functions to keys by
means of the shell bind-to-key command. These commands
may be stored in a file named in the user's home directory
and will then be read by the shell when the editor is initialized.
Flow control is handled by the terminal driver, not by the
shell. The terminal driver normally interprets ^S and ^Q
as a signal to respectively stop and restart output to the
terminal. By default, the shell does not override these
"bindings", but the user may override them by rebinding ^S
or ^Q to functions other than StopFlow and StartFlow.
The functions StopFlow and StartFlow can only be usefully
bound to the keys that the terminal driver interprets as
performing the corresponding flow control functions. In
other words, you cannot simply bind these functions to
other keys in order to have them perform the flow control
operations normally provided by ^S and ^Q.
Keyboard macros can be used to simplify repetitive operations
and reduce typing lengthy commands. For example,
the following lines illustrate how to create a macro to
startup Emacs and have it run the shell inside a buffer:
% ^X(emacs -eshell % ^X)
Notice that this is a multiline macro, since it contains
an embedded newline. The user can give this macro a single
character name, e.g. "e", as follows:
% \ene (escape-n-e).
The macro may then be executed by typing "\exe". It can
also be bound to a key using the bind-to-key command.
Macros can be saved in files and can be reloaded automatically
when the shell starts up. To create a new unnamed
macro, use the StartRemembering function which is bound by
default to ^X(. Subsequent keystrokes, until the StopRemembering,
^X ), function is executed, are remembered as
an "unnamed" keyboard macro. It can contain at most 1024
characters. You are not allowed to begin creating another
macro during macro creation, but it is okay to execute
other macros, provided loops are not created. The unnamed
macro can be executed using the ExecuteUnNamedMacro function,
bound to ^Xe. There is only one unnamed macro.
Users can have up to 128 named macros. To define such a
macro, first create an unnamed macro as above and then
give it a name by executing the DefineNamedMacro function,
bound to \en (escape-n). The function takes a single
character argument which will be the name of the macro.
Any previous macro with that same name will be destroyed.
To execute a named macro simply use the ExecuteNamedMacro
function, bound to \ex, and give it the name of the macro
to be executed. Named macros can also be bound to keys
using the built-in C shell command bind-to-key. Named
keyboard macros can be saved in files and loaded from
files. To save the named macros in a file simply type the
file name on the command line (by itself) and then execute
the SaveMacroFile function bound to ^X^S. To read a file
of previously saved macros type the file name on the command
line and execute the LoadMacroFile function bound to
^X^R. Success in each case is indicated by the erasure of
the file name. It is okay to store macros in several different
macro files. NB: It is not advisable to try to
edit saved macros! If the shell variable macrofiles is
assigned (in the user's file) the names of one or more
files of saved keyboard macros, then those macro files
will be automatically loaded when the shell starts up.
Similarly, the variable savemacros can be assigned the
name of a (single) file in which all named macros will be
saved when the user logs out.
NB: The names of the incremental search functions have
changed since earlier releases of this shell.
Four search functions are available to the user, but are
not bound (by default) to keys. If you want to use them,
use the C shell bind-to-key command to bind them to keys.
When the user executes this function he is placed in a
read/search loop in which the string to be found is built
up character by character. As each new character is added
to the search string the cursor is placed at the end of
the first match on the command line following the position
of the cursor when the function was executed. You can
reexecute the search function while in the loop to cause
the cursor to move to subsequent matches. Type ESC to
exit the loop. This function is similar to IncrementalSearchForward
except that the cursor is placed at the
beginning of the first match on the command line preceding
the position of the cursor when the function was executed.
This function grabs the next character you type and
searches for that character from the position of the cursor
to the end of the command line, leaving the cursor
following the first instance of the character if one is
found. This function is like SearchForward except that it
searches from where the cursor is to the beginning of the
command line.
If the shell variable breakchars is assigned a string,
then the characters in that string are used to determine
word boundaries. The default break characters are " ",
",", ^I, /, \, (, ), [, ], {, }, ., ;, >, <, !, ^, &, and
|. The user defined break characters are used instead of,
not in addition to, the default list.
The display update functions take no advantage of the
capabilities of smart terminals. This will be fixed in
the future.
The command line cannot exceed 1024 characters if characters
are being inserted in the middle of the line; it can
be longer if characters are being inserted at the end, but
once the 1K boundary is passed the previous characters can
no longer be edited or redisplayed.
The interactive input routine performs some initialization
the first time it is called. As a result some things are
not interactively alterable. It is also not possible for
the user to turn off echoing of regular characters or to
take the terminal out of CBREAK mode by means of the stty
command, for example, and have it affect the function of
the shell.
Error conditions within the editor functions are usually
indicated by an audible bell. If you prefer a visual signal
and your terminal has a visible bell capability, then
you should set the variable visiblebell in your file. If
you want an audible bell also, then set both visiblebell
and audiblebell. If you don't want to be told about your
mistakes, you can set the nobell variable.
Quoting with Single and Double Quotes [Toc] [Back]
Enclose strings in single and double quotes to prevent all
or some of the substitutions that remain. Enclosing
strings in ' ' (single quotes) prevents any further interpretation
except history substitution. Enclosing strings
in " " (double quotes) allows further variable and command
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 Substitution).
Alias Substitution [Toc] [Back]
The shell maintains a list of aliases that the alias and
unalias built-in commands can establish, display, and modify.
After the shell scans a command line, it divides the
line into distinct commands and checks the first word of
each command, left to right, to see if it has an alias.
If an alias exists, the text defined as the alias for that
command is reread with the history mechanism, as if the
alias were the previous input line. The words that result
replace the command and argument list. If no reference is
made to the history list, the argument list is left
unchanged.
Thus, if the alias for ls is ls -l, the shell replaces the
command ls /usr with ls -l /usr. The argument list is
left unchanged because there is no reference to the history
list in the command with an alias. Similarly, if the
alias for lookup is grep !^ /etc/passwd, then lookup bill
maps to 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 line: alias lprint 'pr
\!* | lpr'
makes a command that formats its arguments to the line
printer. The ! (exclamation point) 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 new text
is the same as the old, looping is prevented by flagging
it to terminate the alias process. Other loops are
detected and cause an error.
Variable Substitution [Toc] [Back]
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 variable
list, and words that comprise the value of this variable
are referred to in special ways.
You can display and change the values of variables by
using the set and unset commands. Of the variables
referred to by the shell, a number are toggles (variables
that turn 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 that causes the
words of each command to be echoed. The setting of this
variable results from the -v option 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 the
purposes of numeric operations, the null string is considered
to be 0 (zero), and the second and subsequent words
of multiword values are ignored.
After the input line is parsed and alias substitution is
performed, and before each command is executed, variable
substitution is performed, keyed by $ (dollar sign) characters.
You can prevent this expansion by preceding the $
with a \ (backslash) except within " " (double quotes),
where it always occurs, or by using ' ' (single quotes),
where it never occurs. Strings quoted by ` ` (grave
accents) are interpreted later (see Command Substitution),
so variable substitution does not occur there until later,
if at all. A $ is passed unchanged if followed by a space,
tab, or newline.
Input/output redirection is recognized and expanded before
variable expansion occurs. Otherwise, the command name
and complete argument list are expanded together. Therefore,
it is possible for the first (command) word to this
point to generate more than one word, the first of which
becomes the command name, and the rest of which become
arguments.
Unless enclosed in " " or given the :q modifier, the
results of variable substitution can themselves eventually
be command and file name substituted. Within pairs of
double quotes, a variable whose value consists of multiple
words expands to a (portion of a) single word, with the
words of the variable's value separated by spaces. When
you apply the :q modifier to a substitution, the variable
expands to multiple words. The individual words are separated
by spaces 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. Are
replaced by the words assigned to the variable name, each
separated by a space. Braces insulate name from following
characters that would otherwise be part of it. Shell variable
names begin with a letter and consist of up to 20
letters and digits, including the underscore character.
If name is not a shell variable but is set in the
environment, then that value is returned. Be aware
that the : (colon) modifiers and the other forms
given below are not available in this case. Can be
used to select only some of the words from the
value of name. The selector is subjected to variable
substitution and can consist of a single number
or two numbers separated by a - (dash). The
first word of a variable'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 total number of
words in the variable). The * (asterisk) selects
all words. It is not an error for a range to be
empty if the second argument is omitted or in
range. Gives the number of words in the variable.
This can be used as a [selector] (see previous
notation). Substitutes the name of the file from
which command input is being read. An error occurs
if the name is not known. Equivalent to $argv[number].
Equivalent to $argv[*].
You can apply the modifiers :gh, :gt, :gr, :h, :t, :r, :q
and :x to the preceding substitutions. If { } (braces)
appear in the command form, the modifiers must appear
within the braces. Note that the current implementation
allows only one : (colon) modifier on each $ variable
expansion.
The following substitutions cannot be changed with : modifiers.
Substitutes the string 1 if name is set, 0 if it
is not. Substitutes 1 if the current input file name is
known, 0 (zero) if it is not. Substitutes the (decimal)
process number of the (parent) shell. Substitutes a line
from the standard input, with no further interpretation.
Use it to read from the keyboard in a shell script.
Command and File name Substitution [Toc] [Back]
The shell performs command and file name substitution
selectively on the arguments of built-in commands. This
means that it does not expand those parts of expressions
that are not evaluated. For commands that are not internal
(that is, built in) to the shell, the shell substitutes
the command name separately from the argument list. This
occurs very late, after the shell performs input/output
redirection, and in a child of the main shell.
Command Substitution [Toc] [Back]
The shell performs command substitution on a command
string enclosed in ` ` (grave accents). The shell normally
breaks the output from such a command into separate words
at spaces, tabs and newline characters, with null words
being discarded; this text then replaces the original command
string. Within strings surrounded by " " (double
quotes), the shell treats only the newline character as a
word separator, thus preserving spaces and tabs.
In any case, the single final newline character does not
force a new word. Note that it is therefore possible for a
command substitution to yield only part of a word, even if
the command outputs a complete line.
File Name Substitution [Toc] [Back]
If a word contains any of the characters *, ?, [, or { or
begins with a ~ (tilde), 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 a sorted
list of file names that match the pattern.
In a list of words specifying file name substitution, it
is an error for no pattern to match an existing file name,
but it is not required that each pattern match. Only the
character-matching symbols (metacharacters) *, ? and [
imply pattern matching; the characters ~ and { are more
like abbreviations.
In matching file names, the (dot) character at the beginning
of a file name or immediately following a / (slash),
as well as the / character, must be matched explicitly.
The * (asterisk) character matches any string of characters,
including the null string. The ? (question mark)
character matches any single character. The sequence
[abcd] matches any one of the enclosed characters. Within
[ ], a lexical range of characters can be indicated by two
characters separated by a - (dash), as in [a-z]. The
characters that match this pattern are defined by the current
collating sequence. The collating sequence is determined
by the value of the LC_COLLATE or LANG environment
variable.
The ~ (tilde) character at the beginning of a file name is
used to refer to home directories. Standing alone, the ~
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 substitutes
that user's home directory. Thus, ~ken might expand to
/users/ken and ~ken/chmach to /users/ken/chmach. If the ~
(tilde) character is followed by a character other than a
letter or / (slash) or does not appear at the beginning of
a word, it is left undisturbed.
The pattern a{b,c,d}e is a shorthand for abe ace ade.
Left-to-right order is preserved, with the results of the
matches being sorted separately at a low level to preserve
this order. This construct can be nested. Thus, the shell
expands: ~source/s1/{oldls,ls}.c
to the file names: /usr/source/s1/oldls.c
/usr/source/s1/ls.c
The preceding example assumes the home directory for
source is /usr/source. (Note that these files may or may
not exist.)
Similarly, the shell expands: ../{memo,*box}
to the paths: ../memo ../box ../mbox
(Note that memo was not sorted with the results of matching
*box.) As a special case, {, }, and {} are passed
undisturbed.
Redirecting Input and Output [Toc] [Back]
You can redirect the standard input and standard output of
a command with the following syntax: Opens file (which is
first variable, command and file name expanded) as the
standard input. Reads the shell input up to a line that
is identical to word. The word is not subjected to variable,
file name or command substitution; 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 that are substituted have all
spaces, tabs, and newline characters preserved, except for
the final newline character, which is dropped. The resulting
text is placed in an anonymous temporary file and
given to the command as standard input. Uses file as
standard output. If the file does not exist, it is created;
if the file exists, it is truncated, and its previous
contents are lost.
If the noclobber shell variable is set, then the
file must not exist or be a character special file
(for example, a terminal or /dev/null) or an error
results. This helps prevent the accidental destruction
of files. In this case, use the ! (exclamation
point) forms to suppress this check.
The forms involving & (ampersand) route the diagnostic
output into the specified file as well as
the standard output. file is expanded in the same
way as < input file names. Uses file 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 in a pipeline. Thus, unlike some
previous shells, commands run from a shell script have no
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
scripts function as components of pipelines and lets the
shell read its input in blocks.
To redirect diagnostic output through a pipe with the
standard output, use the form |& (vertical bar, ampersand)
rather than | (vertical bar) alone.
Control Flow [Toc] [Back]
The shell contains a number of commands that can be used
to regulate the flow of control in command files (shell
scripts) and (in limited but useful ways) from terminal
input. These commands all operate by forcing the shell to
reread or skip in its input and, because of 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 that the
major keywords appear in a single simple command on an
input line.
If the shell input is not seekable, the shell buffers
input whenever a loop is being read and performs seeks in
the internal buffer to do the rereading implied by the
loop. (To the extent that this allows, backward gotos
succeed on non-seekable inputs.)
Built-In Commands [Toc] [Back]
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. The csh
searches for a csh built-in command first. If a built-in
does not exist, the csh searches through the directories
specified by the environment variable path for a systemlevel
command to execute. If no arguments are specified,
displays all aliases. If name is specified, displays
|