Previous Table of Contents Next



C Shell
Variables that have a capitalized version are set by the C shell at login and reset each time the lowercase version is reset.
cdpath Same as ksh except list of directories is separated by white space not colons.
echo Echo each command after substitution, but before execution.
fignore A list of filename suffixes to ignore at filename completion. Commonly set to '.o'.
filec Enable filename completion. Thus Ctrl-D and Escape have special meaning.
Ctrl-D Print a list of all filenames that start with the preceding string.
Escape Replace preceding string with the longest unambiguous extension.
hardpaths When set, pathnames in the directory stack are resolved to contain no symbolic-links.
histchars A two character string. The first character replaces the default exclamation (!) as the history substitution character. The second replaces the default carat (^) as the quick substitution character.
history The number of lines saved in the history file. The larger the number the less the memory for the csh to use. A number between 100 and 250 is reasonable.
HOME
home
The user's home directory. The expansion of ~ refers to the value of this variable.
ignoreeof If set, the shell ignores Ctrl-D(EOF) from stdin.
mail A list of files the shell checks for mail. If the first word of the list is a number n then the shell checks each file every n minutes.
nobeep Suppress the bell during ambiguous filename completion requests.
noglob Inhibit filename substitution. Often used in shell scripts to prevent further filename expansion.
nonomatch Returns the filename expansion pattern instead of an error if the pattern did not match any files for expansion. Malformed patterns still return an error.
notify If set the shell notifies you immediately when jobs complete. By default the shell notifies you prior to displaying the next prompt.
PATH
path
Same as ksh except the list of paths is separated by white spaces instead of colons.
prompt Same as ksh. Often tested in you .cshrc file to know if the shell is interactive or not. if ( $?prompt == 0 ) exit says that if the prompt is not set then exit, which assumes the shell is not an interactive shell.
savehist The number of lines to save in the .history file when the user logs out. The more lines saved the longer it takes for the C shell to log into the system.
shell Same as the ksh shell.
time Controls the automatic time of commands. Refer to the module on the time command for a complete list of settings.
TERM
term
Same as the ksh TERM variable.
USER
user
Same as the ksh LOGNAME variable.
verbose Display each command after history substitution has occurred.

Default Variable Assignment

The shell assigns default values to the IFS, MAILCHECK, PATH, PS1, and PS2 variables during login. The HOME and MAIL variables are assigned default values by login. You may reassign values to these and any other of the reserved words, but keep in mind how the shell is going to use each variable. Most reserved word assignments are placed in the $HOME/.profile or $HOME/.kshrc. Each time you log in, your reserved variables are set to the desired values without any extra effort on your part.

ARRAYS

An array is a simple data structure containing indexed elements that allows you to store multiple values of the same type in one name. Each element can be accessed by a subscript. The general formats of an array follow.

     variable[subscript]=value   # to assign a value to an array element
     ${variable[subscript]}      # to reference an array element

Notice NO spaces are allowed in either format. Variable is a named variable. The brackets surround the subscript. The subscript may be an integer or an arithmetic expression that returns an integer. The subscript integer must be in the range of 0 to 511. The value must be of the same type as the array.

The ${...} must enclose the name of the array for variable referencing. If no subscript is specified, element zero is used. The following examples help clarify the use of arrays.

   cj> num[0]='363-4804'         # assign 363-4804 to element 0 of num
   cj> num[1]='282-2101'         # assign 282-2101 to element 1 of num
   cj> echo "${num[0]} ${num}"   # display num sub 0 twice
   cj> echo ${num[*]}            # display all elements in num
   cj> echo ${#num[*]}           # display number of elements in num

For more information on data types refer to the typeset command, Module 145. Also refer to the let command, Module 73, and the export command, Module 47, and sections on Variables and Variable Substitution and Referencing.

VARIABLE SUBSTITUTION AND REFERENCING

Variable substitution  is the referencing of the value stored in a variable name. It is performed when a variable is preceded by a $. The shell substitutes the value assigned to the variable in its place. Variable substitution or expansion is performed before filename expansion and before the command is separated into arguments. The following list describes the general format of variable substitution. In the following list word may also be a variable.

$var Expands to the value previously assigned to the variable. The longest possible word following the $ is interpreted as the variable name.
${var} Same as previous but controls what is interpreted as the variable name. By using the braces you can have characters follow immediately after the variable name (${var}EXT). Double digit positional parameters may be referenced using this notation(${12}).
$var[sub]
${var[sub]}
Expands to the value of the element at the subscript sub in array var. The subscript is evaluated before the variable var is expanded.
${var[*]} Expands to all values stored in the elements of an array. Each element is separated by the first character of the IFS variable.
${#var} Expands to the number of characters or bytes used by the value of the variable. If the variable is * or @ then the number of positional parameters are returned.
${#var[*]} Expands to the number of elements stored in the array. Not supported by csh.
${var:-word} Expands to the value of variable if value is nonnull; otherwise, expands to value of word. Not supported by csh.
${var-word} Expands to the value of variable if the variable has been set (null or nonnull); otherwise, expands to the value of word. Not supported by csh.
${var:+word} Expands to the value of variable if variable is nonnull; otherwise, expands to a null. Not supported by csh.
${var+word} Expands to the value of variable if variable is not set (unset); otherwise, expands to value of word. Not supported by csh.
${var:=word} Expands to the value of variable if variable is nonnull; otherwise, expands to the value of word and the variable is assigned the value of word. Not supported by csh.
${var=word} Expands to the value of variable if variable is set; otherwise, expands to the value of word and the variable is assigned the value of word. Not supported by csh.
${var:?} Expands to the value of variable if variable is nonnull; otherwise, expands and displays contents of word and exits the shell. If word is empty, a default message is used. Not supported by csh.
${var?word} Expands to the value of variable if variable is set; otherwise, expands and displays contents of word and exits the shell. If word is empty, a default message is used. Not supported by csh.
${var#pattern} Expands to the value of variable with pattern removed from the left side of variable. If no pattern is matched, then value of variable is used. The smallest matching pattern is removed. Pattern may contain filename generation characters (*, ?, and [...]). Not supported by csh.
${var##pattern) Same as previous syntax except the longest matching pattern in removed from the variable. Not supported by csh.
${var%pattern} Same as previous single # syntax except the smallest matching pattern is removed from the right side of the variable. Not supported by csh.
${var%%pattern} Same as previous % syntax except the longest matching pattern is removed from the right side of the variable. Not supported by csh.
$n Positional parameter. The arguments from the command line. $0 is the name of the command. $1 is the first argument. The last argument can be accessed by eval \$$#


Previous Table of Contents Next