Previous Table of Contents Next


VARIABLE SUBSTITUTION

Variable values can be accessed and manipulated using variable expansion. Basic expansion is done by preceding the variable name with the $ character.

Variable Expansion Format

Variable expansion can also be modified by appending a history substitution modifier (:e, :gh, :gr, :gt, :h, :q, :r, :t, or :x) to the variable name. If braces are used, then the modify operator must also be enclosed.

$variable, ${variable} value of variable
$variable[n], ${variable[n]} value of word n in variable
$variable[nm], ${variable[nm]} values of words n through m in variable
$variable[m], ${variable[m]} values of words 1 through m in variable
$#variable, ${#variable}, $variable[n], ${variable[n]} number of words in variable
$0 name of file from which command input is being read
$n, ${n} current shell argument n (same as $argv[n])
$* all current shell arguments (same as $argv[*])

These may not be used with the history substitution modifiers:

$?variable, ${?variable} return string 1 if variable is set, else return 0
$?0 return string 1 if current input file known, else return 0
$$ process ID of the current shell
$< substitute a line from standard input

ENVIRONMENT VARIABLES

The C shell also has environment variables. They are like regular shell variables, except that environment variables are automatically exported to child processes. The values of some environment and shell variables are shared. The C shell copies the value of the environment variables HOME into home, PATH into path, TERM into term, and USER into user, and copies each back whenever the shell variables are reset.

There are a number of environment variables that allow you to customize your working environment. Some are automatically set by the shell, some have a default value if not set, while others have no value unless specifically set.

Environment Variable Assignment Format

setenv var set environment variable var to null
setenv var value set environment variable var to value
unsetenv variable remove the definition of environment variable

Environment and Predefined Shell Variables

argv number of arguments to the shell ($1, $2, . . .)
cdpath directory search path for cd, chdir, and popd when not given a full pathname or subdirectory
cwd full pathname of the current directory
echo display commands and arguments before execution
fignore filename suffixes to ignore during filename completion
filec enable filename completion. When typed at end of a command line, Ctl-d displays a list of all filenames that begin with the preceding string, and Esc replaces the preceding string with the longest extension.
hardpaths if set, links are resolved in the directory stack
histchars one or two character string; first character replaces !, second character replaces ^ in history substitutions
history number of previous commands accessible by the current shell (default only most recent command)
home pathname of home directory
ignoreeof if set, ignore EOF (Ctl-d) from terminal
mail list of files to check for mail. Number can be given before filename to specify mail checking interval.
nobeep suppress bell during command completion
noclobber if set, > redirections can only be made to new files, and >> redirections can only be made to existing files
noglob if set, disable filename substitution
nonomatch if set, no error is returned on non-matching filename substitution
notify if set, user is immediately notified of completed jobs
path list of pathnames to search for commands
prompt string which is displayed before each command is read. A ! is replaced with current command number (default hostname%, or hostname# for super-user).
savehist number of command entries to save in ~/.history between login sessions
shell pathname of current shell
status return status of last command
time control timing of commands. Can have one or two values, where first value specifies reporting threshold in CPU seconds, and second value specifies which resource to report. Resources given by one or more:
%D average Kbytes of unshared data space
%E elapsed time
%F number of page faults
%I number of input block operations
%K average Kbytes of unshared stack space
%M maximum real memory used
%O number of block output operations
%P total CPU time
%S CPU time used by kernel for user's process
%U CPU time devoted to user process
%W number of swaps
%X average Kbytes of shared memory used
verbose display each command after history substitution


Previous Table of Contents Next
1