csh(1) csh(1)
NAME [Toc] [Back]
csh - a shell (command interpreter) with C-like syntax
SYNOPSIS [Toc] [Back]
csh [-cefinstvxTVX] [command_file] [argument_list ...]
DESCRIPTION [Toc] [Back]
csh is a command language interpreter that incorporates a command
history buffer, C-like syntax, and job control facilities.
Command Options [Toc] [Back]
Command options are interpreted as follows:
-c Read commands from the (single) following argument
which must be present. Any remaining arguments are
placed in argv.
-e C shell exits if any invoked command terminates
abnormally or yields a non-zero exit status.
-f Suppress execution of the .cshrc file in your home
directory, thus speeding up shell start-up time.
-i Force csh to respond interactively when called from a
device other than a computer terminal (such as another
computer). csh normally responds non-interactively.
If csh is called from a computer terminal, it always
responds interactively, regardless of which options are
selected.
-n Parse but do not execute commands. This is useful for
checking syntax in shell scripts. All substitutions
are performed (history, command, alias, etc.).
-s Take command input from the standard input.
-t Read and execute a single line of input.
-v Set the verbose shell variable, causing command input
to be echoed to the standard output device after
history substitutions are made.
-x Set the echo shell variable, causing all commands to be
echoed to the standard error immediately before
execution.
-T Disable the tenex features which use the ESC key for
command/file name completion and CTRL-D for listing
available files (see the CSH UTILITIES section below)
Hewlett-Packard Company - 1 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
-V Set the verbose variable before .cshrc is executed so
that all .cshrc commands are also echoed to the
standard output.
-X Set the echo variable before .cshrc is executed so that
all .cshrc commands are also echoed to the standard
output.
After processing the command options, if arguments remain in the
argument list, and the -c, -i, -s, or -t options were not specified,
the first remaining argument is taken as the name of a file of
commands to be executed.
COMMANDS [Toc] [Back]
A simple command is a sequence of words, the first of which specifies
the command to be executed. A sequence of simple commands separated
by vertical bar (|) characters forms a pipeline. The output of each
command in a pipeline becomes the input for the next command in the
pipeline. Sequences of pipelines can be separated by semicolons (;)
which causes them to be executed sequentially. A sequence of
pipelines can be executed in background mode by adding an ampersand
character (&) after the last entry.
Any pipeline can be placed in parentheses to form a simple command
which, in turn, can be a component of another pipeline. Pipelines can
also be separated by || or && indicating, as in the C language, that
the second pipeline is to be executed only if the first fails or
succeeds, respectively.
Jobs [Toc] [Back]
csh associates a job with each pipeline and keeps a table of current
jobs (printed by the jobs command) and assigns them small integer
numbers. When a job is started asynchronously using &, the shell
prints a line resembling:
[1] 1234
indicating that the job which was started asynchronously was job
number 1 and had one (top-level) process, whose process id was 1234.
If you are running a job and want to do something else, you can type
the currently defined suspend character (see termio(7)) which sends a
stop signal to the current job. csh then normally indicates that the
job has been `Stopped', and prints another prompt. You can then
manipulate the state of this job, putting it in the background with
the bg command, run some other commands, and then eventually bring the
job back into the foreground with the foreground command fg. A
suspend takes effect immediately and is like an interrupt in that
pending output and unread input are discarded when it is typed. There
is a delayed suspend character which does not generate a stop signal
until a program attempts to read(2) it. This can usefully be typed
Hewlett-Packard Company - 2 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
ahead when you have prepared some commands for a job which you want to
stop after it has read them.
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 giving the command stty tostop (see stty(1)).
If you set this tty option, background jobs stop when they try to
produce output, just as they do when they try to read input. Keyboard
signals and line-hangup signals from the terminal interface are not
sent to background jobs on such systems. This means that background
jobs are immune to the effects of logging out or typing the interrupt,
quit, suspend, and delayed suspend characters (see termio(7)).
There are several ways to refer to jobs in the shell. The character %
introduces a job name. If you wish to refer to job number 1, you can
name it as %1. Just naming a job brings it to the foreground; thus %1
is a synonym for fg %1 , bringing job 1 back into the foreground.
Similarly, typing %1 & resumes job 1 in the background. Jobs can also
be named by prefixes of the string typed in to start them if these
prefixes are unambiguous; thus %ex normally restarts a suspended ex(1)
job, if there is only one suspended job whose name begins with the
string ex. It is also possible to say %?string which specifies a job
whose text contains string, if there is only one such job.
csh maintains a notion of the current and previous jobs. In output
pertaining to jobs, the current job is marked with a + and the
previous job with a -. The abbreviation %+ refers to the current job
and %- refers to the previous job. For close analogy with the syntax
of the history mechanism (described below), %% is also a synonym for
the current job.
csh learns immediately whenever a process changes state. It normally
informs you whenever a job becomes blocked so that no further progress
is possible, but only just before printing a prompt. This is done so
that it does not otherwise disturb your work. If, however, you set
the shell variable notify, csh notifies you immediately of changes in
status of background jobs. There is also a csh built-in command
called notify which marks a single process so that any status change
is immediately reported. By default, notify marks the current
process. Simply type notify after starting a background job to mark
it.
If you try to leave the shell while jobs are stopped, csh sends the
warning message: You have stopped jobs. Use the jobs command to see
what they are. If you do this or immediately try to exit again, csh
does not warn you a second time, and the suspended jobs are terminated
(see exit(2)).
Built-In Commands [Toc] [Back]
Built-in commands are executed within the shell without spawning a new
process. If a built-in command occurs as any component of a pipeline
Hewlett-Packard Company - 3 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
except the last, it is executed in a subshell. The built-in commands
are:
alias
alias name
alias name wordlist
The first form prints all aliases. The second form
prints the alias for name. The third form assigns the
specified wordlist as the alias of name. Command and
file name substitution are performed on wordlist. name
cannot be alias or unalias.
bg [%job ...]
Put the current (job not specified) or specified jobs
into the background, continuing them if they were
stopped.
break Causes execution to resume after the end of the nearest
enclosing foreach or while. The remaining commands on
the current line are executed. Multi-level breaks are
thus possible by writing them all on one line.
breaksw Causes a break from a switch, resuming after the endsw.
case label:
A label in a switch statement as discussed below.
cd
cd directory_name
chdir
chdir directory_name
Change the shell's current working directory to
directory_name. If not specified, directory_name
defaults to your home directory.
If directory_name is not found as a subdirectory of the
current working directory (and does not begin with /, ./,
or ../), each component of the variable cdpath is checked
to see if it has a subdirectory directory_name. Finally,
if all else fails, csh treats directory_name as a shell
variable. If its value begins with /, this is tried to
see if it is a directory. See also cd(1).
continue
Continue execution of the nearest enclosing while or
foreach. The rest of the commands on the current line
are executed.
default:
Labels the default case in a switch statement. The
default should come after all other case labels.
Hewlett-Packard Company - 4 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
dirs Prints the directory stack; the top of the stack is at
the left; the first directory in the stack is the current
directory.
echo wordlist
echo -n wordlist
The specified words are written to the shell's standard
output, separated by spaces, and terminated with a newline
unless the -n option is specified. See also
echo(1).
else
end
endif
endsw See the descriptions of the foreach, if, switch, and
while statements below.
eval arguments ...
(Same behavior as sh(1).) arguments are read as input to
the shell and the resulting command(s) executed. This is
usually used to execute commands generated as the result
of command or variable substitution, since parsing occurs
before these substitutions.
exec command
The specified command is executed in place of the current
shell.
exit
exit (expression)
csh exits either with the value of the status variable
(first form) or with the value of the specified
expression (second form).
fg [%job ...]
Brings the current (job not specified) or specified jobs
into the foreground, continuing them if they were
stopped.
foreach name (wordlist)
...
end The variable name is successively set to each member of
wordlist and the sequence of commands between this
command and the matching end are executed. (Both foreach
and end must appear alone on separate lines.)
The built-in command continue can be used to continue the
loop prematurely; the built-in command break to terminate
it prematurely. When this command is read from the
terminal, the loop is read once, prompting with ? before
any statements in the loop are executed. If you make a
Hewlett-Packard Company - 5 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
mistake while typing in a loop at the terminal, use the
erase or line-kill character as appropriate to recover.
glob wordlist
Like echo but no \ escapes are recognized and words are
delimited by null characters in the output. Useful in
programs that use the shell to perform file name
expansion on a list of words.
goto word
The specified word is file name and command expanded to
yield a string of the form label. The shell rewinds its
input as much as possible and searches for a line of the
form label: possibly preceded by blanks or tabs.
Execution continues after the specified line.
hashstat
Print a statistics line indicating how effective the
internal hash table has been at locating commands (and
avoiding execs). An exec is attempted for each component
of the path where the hash function indicates a possible
hit, and in each component that does not begin with a /.
history [-h] [-r] [n]
Displays the history event list. If n is given, only the
n most recent events are printed. The -r option reverses
the order of printout to be most recent first rather than
oldest first. The -h option prints the history list
without leading numbers for producing files suitable for
the source command.
if (expression) command
If expression evaluates true, the single command with
arguments is executed. Variable substitution on command
happens early, at the same time it does for the rest of
the if command. command must be a simple command; not a
pipeline, a command list, a parenthesized command list,
or an aliased command. Input/output redirection occurs
even if expression is false, meaning that command is not
executed (this is a bug).
if (expression1) then
...
else if (expression2) then
...
else
...
endif If expression1 is true, all commands down to the first
else are executed; otherwise if expression2 is true, all
commands from the first else down to the second else are
executed, etc. Any number of else-if pairs are possible,
Hewlett-Packard Company - 6 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
but only one endif is needed. The else part is likewise
optional. (The words else and endif must appear at the
beginning of input lines. The if must appear alone on
its input line or after an else.)
jobs [-l]
Lists active jobs. The -l option lists process IDs in
addition to the usual information.
kill % job
kill - sig % job ...
kill pid
kill - sig pid...
kill -l Sends either the TERM (terminate) signal or the specified
signal to the specified jobs or processes. Signals are
either given by number or by names (as given in
/usr/include/signal.h, stripped of the SIG prefix (see
signal(2)). The signal names are listed by kill -l.
There is no default, so kill used alone does not send a
signal to the current job. If the signal being sent is
TERM (terminate) or HUP (hangup), the job or process is
sent a CONT (continue) signal as well. See also kill(1).
limit[-h][resource][maximum_use]
Limits the usage by the current process and each process
it creates not to (individually) exceed maximum_use on
the specified resource. If maximum_use is not specified,
then the current limit is displayed; if resource is not
specified, then all limitations are given.
If the -h flag is specified, the hard limits are used
instead of the current limits. The hard limits impose a
ceiling on the values of the current limits. Only the
superuser can raise the hard limits, but a user can lower
or raise the current limits within the legal range.
Controllable resources currently include:
addresspace Maximum address space in bytes
for a process
coredumpsize Size of the largest core dump
that is created
cputime Maximum number of CPU seconds to
be used by each process
datasize Maximum growth of the data
region allowed beyond the end of
the program text
Hewlett-Packard Company - 7 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
descriptors Maximum number of open files for
each process
filesize Largest single file that can be
created
memoryuse Maximum size to which a
process's resident set size can
grow
stacksize Maximum size of the
automatically extended stack
region
The maximum_use argument can be specified as a floatingpoint
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 can be used. filesize can be lowered by an
instance of csh, but can only be raised by an instance
whose effective user ID is root. For more information,
refer to the documentation for the ulimit system call.
login Terminates a login shell, replacing it with an instance
of /usr/bin/login. This is one way to log off, included
for compatibility with sh(1).
logout Terminates a login shell. Especially useful if ignoreeof
is set. A similar function, bye, which works for
sessions that are not login shells, is provided for
historical reasons. Its use is not recommended because
it is not part of the standard BSD csh and may not be
supported in future releases.
newgrp Changes the group identification of the caller; for
details see newgrp(1). A new shell is executed by newgrp
so that the current shell environment is lost.
nice
nice +number
nice command
nice +number command
The first form sets the nice (run command priority) for
this shell to 4 (the default). The second form sets the
priority to the given number. The final two forms run
command at priority 4 and number respectively. The user
with appropriate privileges can raise the priority by
specifying negative niceness using nice -number ...
command is always executed in a sub-shell, and
restrictions placed on commands in simple if statements
Hewlett-Packard Company - 8 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
apply. See also nice(1).
nohup [command]
Without an argument, nohup can be used in shell scripts
to cause hangups to be ignored for the remainder of the
script. With an argument, causes the specified command
to be run with hangups ignored. All processes executed
in the background with & are effectively nohuped as
described under Jobs in the COMMANDS section.
notify [job ...]
Causes the shell to notify the user asynchronously when
the status of the current (job not specified) or
specified jobs changes; normally notification is
presented before a prompt. This is automatic if the
shell variable notify is set.
onintr [-] [label]
Controls the action of the shell on interrupts. With no
arguments, onintr restores the default action of the
shell on interrupts, which action is to terminate shell
scripts or return to the terminal command input level.
If - is specified, all interrupts are ignored. If a
label is given, the shell executes a goto label when an
interrupt is received or a child process terminates
because it was interrupted.
If the shell is running in the background and interrupts
are being ignored, onintr has no effect; interrupts
continue to be ignored by the shell and all invoked
commands.
popd [+n]
Pops the directory stack, returning to the new top
directory. With an argument, discards the nth entry in
the stack. The elements of the directory stack are
numbered from 0 starting at the top. A synonym for popd,
called rd, is provided for historical reasons. Its use
is not recommended because it is not part of the standard
BSD csh and may not be supported in future releases.
pushd [name] [+n]
With no arguments, pushd exchanges the top two elements
of the directory stack. Given a name argument, pushd
changes to the new directory (using cd) and pushes the
old current working directory (as in csw) onto the
directory stack. With a numeric argument, pushd rotates
the nth argument of the directory stack around to be the
top element and changes to that directory. The members
of the directory stack are numbered from the top starting
at 0. A synonym for pushd, called gd, is provided for
Hewlett-Packard Company - 9 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
historical reasons. Its use is not recommended since it
is not part of the standard BSD csh and may not be
supported in future releases.
rehash Causes the internal hash table of the contents of the
directories in the path variable to be recomputed. This
is needed if new commands are added to directories in the
path while you are logged in. This should only be
necessary if you add commands to one of your own
directories or if a systems programmer changes the
contents of one of the system directories.
repeat count command
The specified command (which is subject to the same
restrictions as the command in the one-line if statement
above) is executed count times. I/O redirections occur
exactly once, even if count is 0.
set
set name
set name=word
set name[index]=word
set name=(wordlist)
The first form of set shows the value of all shell
variables. Variables whose value is other than a single
word print as a parenthesized word list. The second form
sets name to the null string. The third form sets name
to the single word. The fourth form sets the indexth
component of name to word; this component must already
exist. The final form sets name to the list of words in
wordlist. In all cases the value is command and filename
expanded.
These arguments can be repeated to set multiple values in
a single set command. Note, however, that variable
expansion happens for all arguments before any setting
occurs.
setenv name value
Sets the value of environment variable name to be value,
a single string. The 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.
shift [variable]
If no argument is given, the members of argv are shifted
to the left, discarding argv[1]. An error occurs if argv
is not set or has less than two strings assigned to it.
When variable is specified, shift performs the same
function on the specified variable.
Hewlett-Packard Company - 10 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
source [-h] name
csh reads commands from name. source commands can be
nested, but if nested too deeply the shell may run out of
file descriptors or reach the max stack size (see
maxssiz(5)). An error in a source at any level
terminates all nested source commands. Normally, input
during source commands is not placed on the history list.
The -h option can be used to place commands in the
history list without being executing them.
stop [%job ...]
Stops the current (no argument) or specified jobs
executing in the background.
suspend Causes csh to stop as if it had been sent a suspend
signal. Since csh normally ignores suspend signals, this
is the only way to suspend the shell. This command gives
an error message if attempted from a login shell.
switch (string)
case str1:
...
breaksw
...
default:
...
breaksw
endsw Each case label (str1) is successively matched against
the specified string which is first command and file name
expanded. The form of the case labels is the Pattern
Matching Notation with the exception that non-matching
lists in bracket expressions are not supported (see
regexp(5)). If none of the labels match before a default
label is found, 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 default labels
as in C. If no label matches and there is no default,
execution continues after the endsw.
time [command]
When command is not specified, a summary of time used by
this shell and its children is printed. If specified,
the simple command is timed and a time summary as
described under the time variable is printed. If
necessary, an extra shell is created to print the time
statistic when the command completes.
umask [value]
The current file creation mask is displayed (value not
Hewlett-Packard Company - 11 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
specified) or set to the specified value. The mask is
given in octal. Common values for the mask are 002,
which gives all permissions to the owner and group and
read and execute permissions to all others, or 022, which
gives all permissions to the owner, and only read and
execute permission to the group and all others. See also
umask(1).
unalias pattern
All aliases whose names match the specified pattern are
discarded. Thus, all aliases are removed by unalias *.
No error occurs if pattern does not match an existing
alias.
unhash Use of the internal hash table to speed location of
executed programs is disabled.
unset pattern
All variables whose names match the specified pattern are
removed. Thus, all variables are removed by unset *;
this has noticeably undesirable side-effects. No error
occurs if pattern matches nothing.
unsetenv pattern
Removes all variables whose names match the specified
pattern from the environment. See also the setenv
command above and printenv(1).
wait Waits for all background jobs to terminate. If the shell
is interactive, an interrupt can disrupt the wait, at
which time the shell prints names and job numbers of all
jobs known to be outstanding.
while (expression)
...
end While the specified expression evaluates non-zero, the
commands between the while and the matching end are
evaluated. break and continue can be used to terminate
or continue the loop prematurely. (The while and end
must appear alone on their input lines.) If the input is
a terminal (i.e., not a script), prompting occurs the
first time through the loop as for the foreach statement.
%job Brings the specified job into the foreground.
%job & Continues the specified job in the background.
@
@ name=expression
@ name[index]=expression
Hewlett-Packard Company - 12 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
The first form prints the values of all the shell
variables. The second form sets the specified name to
the value of expression. If the expression contains <,
>, &, or |, at least this part of the expression must be
placed within parentheses. The third form assigns the
value of expression to the indexth argument of name.
Both name and its indexth component must already exist.
The operators *=, +=, etc., are available as in C. White
space can optionally separate the name from the
assignment operator. However, spaces are mandatory in
separating components of expression which would otherwise
be single words.
Special postfix ++ and -- operators increment and
decrement name, respectively (e.g., @ i++).
Non-Built-In Command Execution [Toc] [Back]
When a command to be executed is not a built-in command, csh attempts
to execute the command via exec(2). Each word in the variable path
names a directory in which the shell attempts to find the command (if
the command does not begin with /). If neither -c nor -t is given,
the shell hashes the names in these directories into an internal table
so that an exec is attempted only in those directories where the
command might possibly reside. This greatly speeds command location
when a large number of directories are present in the search path. If
this mechanism has been turned off (via unhash), or if -c or -t was
given, or if any directory component of path does not begin with a /,
the shell concatenates the directory name and the given command name
to form a path name of a file which it then attempts to execute.
Commands placed inside parentheses are always executed in a subshell.
Thus
(cd ; pwd)
prints the home directory then returns to the current directory upon
completion, whereas:
cd ; pwd
remains in the home directory upon completion.
When commands are placed inside parentheses, it is usually to prevent
chdir from affecting the current shell.
If the file has execute permissions but is not an executable binary
file, it is assumed to be a script file, which is a file of data for
an interpreter that is executed as a separate process.
Hewlett-Packard Company - 13 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
csh first attempts to load and execute the script file (see exec(2)).
If the first two characters of the script file are #!, exec(2) expects
an interpreter path name to follow and attempts to execute the
specified interpreter as a separate process to read the entire script
file.
If no #! interpreter is named, and there is an alias for the shell,
the words of the alias are inserted at the beginning of the argument
list to form the shell command. The first word of the alias should be
the full path name of the command to be used. Note that this is a
special, late-occurring case of alias substitution, which inserts
words into the argument list without modification.
If no #! interpreter is named and there is no shell alias, but the
first character of the file is #, the interpreter named by the $shell
variable is executed (note that this normally would be /usr/bin/csh,
unless the user has reset $shell). If $shell is not set, /usr/bin/csh
is executed.
If no !# interpreter is named, and there is no shell alias, and the
first character of the file is not #, /usr/bin/sh is executed to
interpret the script file.
History Substitutions [Toc] [Back]
History substitutions enable you to repeat commands, use words from
previous commands as portions of new commands, repeat arguments of a
previous command in the current command, and fix spelling or typing
mistakes in an earlier command.
History substitutions begin with an exclamation point (!).
Substitutions can begin anywhere in the input stream, but cannot be
nested. The exclamation point can be preceded by a backslash to
cancel its special meaning. For convenience, an exclamation point is
passed to the parser unchanged when it is followed by a blank, tab,
newline, equal sign, or left parenthesis. Any input line that
contains history substitution is echoed on the terminal before it is
executed for verification.
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 number of previous commands saved is controlled by the history
variable. The previous command is always saved, regardless of its
value. Commands are numbered sequentially from 1.
You can refer to previous events by event number (such as !10 for
event 10), relative event location (such as !-2 for the second
previous event), full or partial command name (such as !d for the last
event using a command with initial character d), and string expression
(such as !?mic? referring to an event containing the characters mic).
Hewlett-Packard Company - 14 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
These forms, without further modification, simply reintroduce the
words of the specified events, each separated by a single blank. As a
special case, !! is a re-do; it refers to the previous command.
To select words from a command, use a colon (:) and a designator for
the desired words after the event specification. The words of an
input line are numbered from zero. The basic word designators are:
0 First word (i.e., the command name itself).
n nth word.
^ First argument. (This is equivalent to 1.)
$ Last word.
a-b Range of words from a through b. Special cases are -y, an
abbreviation for ``word 0 through word y''; and x-, which
means ``word x up to, but not including, word $''.
* Range from the second word through the last word.
% Used with a search sequence to substitute the immediately
preceding matching word.
The colon separating the command specification from the word
designator can be omitted if the argument selector begins with a ^, $,
*, -, or %.
After word designator can be followed by a sequence of modifiers, each
preceded by a colon. The following modifiers are defined:
h Use only the first component of a path name by removing all
following components.
r Use the root file name by removing any trailing suffix
(.xxx).
e Use the file name's trailing suffix (.xxx) by removing the
root name.
s /l/r
substitute the value of r for the value l in the indicated
command.
t Use only the final file name of a path name by removing all
leading path name components.
& Repeat the previous substitution.
Hewlett-Packard Company - 15 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
p Print the new command but do not execute it.
q Quote the substituted words, preventing further
substitutions.
x Like q, but break into words at blanks, tabs and newlines.
g Use a global command as a prefix to another modifier to
cause the specified change to be made globally. All words
in the command are changed, one change per word, and each
string enclosed in single quotes (') or double quotes (") is
treated as a single word.
Unless preceded by a g, the modification is applied only to the first
modifiable word. An error results if a substitution is attempted and
cannot be completed (i.e., if you ask for a substitution of !11 on a
history buffer containing only 10 commands).
The left hand side of substitutions are strings; not regular
expressions in the sense of HP-UX editors. Any character can be used
as the delimiter in place of a slash (/). Use a backslash to quote a
delimiter character if it is used in the l or r string. The character
& in the right-hand side is replaced by the text from the left. A \
also quotes &. A null l string uses the previous string either from
an l or from a contextual scan string s in !?s?. The trailing
delimiter in the substitution can be omitted if a new-line character
follows immediately, as may the trailing ? in a contextual scan.
A history reference can be given without an event specification (as in
!$). In this case, the reference is to the previous command unless a
previous history reference occurred on the same line, in which case
this form repeats the previous reference. Thus
!?foo?^ !$
gives the first and last arguments from the command matching ?foo?.
A special abbreviation of a history reference occurs when the first
non-blank 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 fixes the spelling of
lib in the previous command.
Finally, a history substitution can be enclosed within curly braces
{ } if necessary to insulate it from the characters which follow.
Thus, after
ls -ld ~paul
one could execute !{l}a to do
Hewlett-Packard Company - 16 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
ls -ld ~paula
while !la would look for a command starting with la.
Quoting with Single and Double Quotes [Toc] [Back]
The quotation of strings by single quotes (') and double quotes (")
can be used to prevent all or some of the remaining substitutions.
Strings enclosed in single quotes are protected from any further
interpretation. Strings enclosed in double quotes are still variableand
command-expanded as described below.
In both cases the resulting text becomes (all or part of) a single
word. Only in one special case (see Command Substitution below) does
a double-quoted string yield parts of more than one word; singlequoted
strings never do.
Alias Substitution [Toc] [Back]
csh maintains a list of aliases that can be established, displayed,
and modified by the alias and unalias commands. After a command line
is scanned, it is parsed into distinct commands and the first word of
each command, left-to-right, is checked to see if it has an alias. If
it does, the text which is the alias for that command is reread with
the history mechanism available as if that command was the previous
input line. The resulting words 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 command ls /usr maps to ls -l
/usr, leaving the argument list undisturbed. Similarly, if the alias
for lookup was grep !^ /etc/passwd, lookup bill maps to grep bill
/etc/passwd .
If an alias is found, the word transformation of the input text is
performed and the aliasing process begins again on the re-formed input
line. Looping is prevented if the first word of the new text is the
same as the old by flagging it to prevent further aliasing. Other
loops are detected and cause an error.
Note that the mechanism allows aliases to introduce parser metasyntax.
Thus:
alias print 'pr \!* | lp'
makes a command that uses pr(1) to print its arguments on the line
printer.
Expressions [Toc] [Back]
Some of the built-in commands take expressions in which the operators
are similar to those of C, with the same precedence. These
expressions appear in the @, exit, if, and while commands. The
following operators are available (shown in order of increasing
Hewlett-Packard Company - 17 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
precedence):
|| && | ^ & == != =~ !~ <= >= < > << >> + - * / % ! ~ ( )
The following list shows the grouping of these operators. The
precedence decreases from top to bottom in the list:
* / %
+ -
<< >>
<= >= < >
== != =~ !~
The operators ==, !=, =~, and !~ compare their arguments as strings;
all others operate on numbers. The operators =~ and !~ are similar to
!= and ==, except that the right-hand side is a pattern (containing
*s, ?s, and instances of [...]) against which the left hand operand is
matched. This reduces the need for use of the switch statement in
shell scripts when all that is really needed is pattern matching.
Strings beginning with 0 are considered octal numbers. Null or
missing arguments are considered 0. The result of all expressions are
strings that represent decimal numbers. It is important to note that
no two components of an expression can appear in the same word. These
components should be surrounded by spaces except when adjacent to
components of expressions that are syntactically significant to the
parser: -, &, |, <, >, (, and ).
Also available in expressions as primitive operands are command
executions enclosed in curly braces ({ }) and file enquiries of the
form -l filename, 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 filename is command- and file-name expanded then tested
to see if it has the specified relationship to the real user. If the
file does not exist or is inaccessible, all inquiries return false
(0). Command executions succeed, returning true, if the command exits
with status 0; otherwise they fail, returning false. If more detailed
status information is required, the command should be executed outside
of an expression and the status variable examined.
Hewlett-Packard Company - 18 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
Control of the Flow [Toc] [Back]
csh 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 parts of its input and, due to the
implementation, restrict the placement of some of the commands.
The foreach, switch, and while statements, as well as the if-then-else
form of the if statement require that the major keywords appear in a
single simple command on an input line as shown below.
If the shell's input is not seekable, the shell buffers input whenever
a loop is being read and performs seeks in this internal buffer to
accomplish the rereading implied by the loop. (To the extent that
this allows, backward gotos succeed on non-seekable inputs.)
Signal Handling [Toc] [Back]
csh normally ignores quit signals. Jobs running in background mode
are immune to signals generated from the keyboard, including hangups.
Other signals have the values which the shell inherited from its
parent. csh's handling of interrupts and terminate signals in shell
scripts can be controlled by onintr. Login shells catch the terminate
signal; otherwise this signal is passed on to children from the state
in the shell's parent. In no case are interrupts allowed when a login
shell is reading the file .logout.
Command Line Parsing [Toc] [Back]
csh splits input lines into words at blanks and tabs. The following
exceptions (parser metacharacters) are considered separate words:
& ampersand;
| vertical bar;
; semicolon;
< less-than sign;
> greater-than sign;
( left parenthesis;
) right parenthesis;
&& double ampersand;
|| double vertical bar;
<< double less-than sign;
>> double greater-than sign;
# comment delimiter
The backslash (\) removes the special meaning of these parser
metacharacters. A parser metacharacter preceded by a backslash is
interpreted as its ASCII value. A newline character (ASCII 10)
preceded by a backslash is equivalent to a blank.
Strings enclosed in single or double quotes form parts of a word.
Metacharacters in these strings, including blanks and tabs, do not
form separate words. Within pairs of backslashes or quotes, a newline
Hewlett-Packard Company - 19 - HP-UX 11i Version 2: August 2003
csh(1) csh(1)
preceded by a backslash gives a true newline character.
When csh's input is not a terminal, the # character introduces a
comment terminated by a newline.
CSH VARIABLES [Toc] [Back]
csh maintains a set of variables. Each variable has a value equal to
zero or more strings (words). Variables have names consisting of up
to 80 letters and digits starting with a letter. The underscore
character is considered a letter. The value of a variable may be
displayed and changed by using the set and unset commands. Som
|