Variables in the C shell

The C shell uses two types of variables, environment variables and shell variables to store information about the way it is to operate.

Environment variables are:

Shell variables are:

Common environment variables are:

EDITOR
name/location of default editor (used in mail programs etc.)
HOME
home directory
PATH
list of directories to search for programs
PRINTER
name/location of default printer
SHELL
name of shell
TERM
name of terminal device
USER
user identity
VISUAL
is used by many programs for name/location of default editor

Some common shell variables are:

history
number of previous commands stored
home
home directory
ignoreeof
if set, the EOF control sequence will not exit the login shell
notify
if set, the shell will notify any changes in the status of background jobs
path
directories to search for executables
prompt
current shell prompt
savehist
number of history commands to save from one login session to the next
shell
location of shell program

Note, that some variables exist as both environment variables and shell variables, but because the environment version has an upper case identifier and the shell version a lower case identifier they are separate distinct variables. However, for these particular variables (HOME/home, PATH/path and TERM/term) the shell will automatically change both, whichever you set.

When a C shell is started it will set home, path, and term to be the same as the HOME, PATH and TERM environment variables. The shell variable shell will be set to the directory location of the csh executable or whichever shell you are using.

Although most executables look to the environment variables for information about your own personal configurations (for example, the EDITOR environment variable will be used by some mail programs) this is not always guaranteed.

Help: for more information see csh(1) and in this document, on files associated with the C shell.

Environment Variables

The printenv command will list all currently set environment variables. For example,

% printenv
HOME=/u1/mary
SHELL=/bin/csh
PATH=(/u1/mary/bin /bin /usr/bin /usr/local/bin)
USER=mary
TERM=vt100
EDITOR=/usr/local/bin/emacs
PRINTER=central

To add a new variable to the list, or modify an existing one, use the setenv command,

% setenv PRINTER central

To remove an environment variable use the unsetenv command.

% unsetenv PRINTER

Help: for more information see csh(1).

Shell Variables

Set a new shell variable with the set command.

% set message=hello
% echo $message
hello

Note, there are no spaces around the equals sign. The dollar sign, $, tells echo to display the value of the variable message, i.e. hello instead of the string message.

Some shell variables have no parameters, for example set ignoreof simply switches that setting on. Multiple values can be set using () brackets.

A list of the current shell variables can be listed using the command set. Any changes made will only affect the current shell, unless placed in the .cshrc file.

% set
argv ()
message hello
ignoreof
history 40
home /u1/mary
path (/u1/mary/bin /bin /usr/bin /usr/local/bin)
noclobber
shell /bin/csh

To remove a shell variable use unset.

% unset message

Help: for more information see csh(1). See the section on Predefined and Environment variables for explanation of individual shell variables.