HP-UX Reference (11i v2 03/08) - 1 User Commands A-M (vol 1)
c
csh(1) csh(1)
CSH VARIABLES
csh maintains a set of variables. Each variable has a value equal to zero or more strings (words). Vari-
ables 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. Some of the variables are Boolean, that is, the shell does not care what their value is,
only whether they are set or not.
Some operations treat variables numerically. The at sign (
@) command permits numeric calculations to
be performed and the result assigned to a variable. The null string is considered to be zero, and any sub-
sequent words of multi-word values are ignored.
After the input line is aliased and parsed, and before each command is executed, variable expansion is
performed keyed by the dollar sign (
$) character. Variable expansion can be prevented by preceding the
dollar sign with a backslash character (
\
) except within double quotes (") where substitution always
occurs. Variables are never expanded if enclosed in single quotes. Strings quoted by single quotes are
interpreted later (see Command Substitution ) so variable substitution does not occur there until later, if
at all. A dollar sign is passed unchanged if followed by a blank, tab, or end-of-line.
Input/output redirections are recognized before variable expansion, and are variable expanded
separately. Otherwise, the command name and entire argument list are expanded together.
Unless enclosed in double quotes or given the
:q modifier, the results of variable substitution may even-
tually be command and file name substituted. Within double quotes, a variable whose value consists of
multiple words expands to a portion of a single word, with the words of the variable’s value separated by
blanks. When the
:q modifier is applied to a substitution, the variable expands to multiple words with
each word separated by a blank and quoted to prevent later command or file name substitution.
The following metasequences are provided for introducing variable values into the shell input. Except as
noted, it is an error to reference a variable that is not set.
$variable_name
${variable_name}
When interpreted, this sequence is replaced by the words of the value of the variable
variable_name , each separated by a blank. Braces insulate variable_name from subse-
quent characters that would otherwise be interpreted to be part of the variable name itself.
If variable_name is not a
csh variable, but is set in the environment, that value is used.
Non-
csh variables cannot be modified as shown below.
$variable_name[selector]
${variable_name[selector]
}
This modification selects only some of the words from the value of variable_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 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 the total number of words in the variable ($#variable_name). An asterisk
metacharacter used as a selector selects all words.
$#variable_name
${#variable_name}
This form gives the number of words in the variable, and is useful for forms using a [selec-
tor]option.
$0 This form substitutes the name of the file from which command input is being read. An
error occurs if the file name is not known.
$number
${number}
This form is equivalent to an indexed selection from the variable argv ($argv[number]).
$* This is equivalent to selecting all of argv ($argv[*]).
The modifiers
:h, :t, :r, :q, and :x can be applied to the substitutions above, as can :gh, :gt, and
:gr. If curly braces ({}) appear in the command form, the modifiers must appear within the braces.
The current implementation allows only one : modifier on each $d expansion.
The following substitutions cannot be modified with
: modifiers:
$?variable_name
HP-UX 11i Version 2: August 2003 − 12 − Hewlett-Packard Company Section 1−−141