DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Configuring and working with the shells

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 (see ``Automating frequent tasks''). 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.
Next topic: Setting shell variables
Previous topic: What happens when you log in

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003