DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Customizing your environment

Understanding variables

The shells provide facilities for storing useful information and transferring it between programs. Among these is the ability to handle variables (named pieces of text or numbers, that can be used in a variety of ways).

Variables have many uses. For example, if you frequently need to cd to /u/work/systems/Admin, you could define the variable ADMIN to be /u/work/systems/Admin, then type cd $ADMIN to change to that directory.

Variables consist of a name (or label) and an associated value. In the example above, the variable is named ADMIN; its value is /u/work/systems/Admin. You refer to the value of a variable by prefixing its name with a ``$'' symbol. When the shell reads the ``$'' symbol it checks the subsequent text to see if it is a variable name (such as NAME), and replaces the input text $NAME with the value of NAME.

There are two types of variable available to you:


Shell variables
These are created within a shell and are used to temporarily store information and to control the execution of shell scripts. Shell variables are not visible to any other program, and are lost when the shell terminates.

Environment variables
All programs running on the system have a special memory area called an environment. When a program is run, it inherits a copy of its parent program's environment, complete with any variables stored in it. Environment variables are used to pass configuration information to child processes executed by the shell. They are created by exporting a shell variable into the shell's environment, which makes them visible to all programs subsequently executed under that shell (see ``Exporting variables to the environment''). However, it is not possible for a child to alter its parent shell's environment.
The sections below explain how to create and refer to shell variables and environment variables.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004