DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with the UNIX system shell

Using shell variables

Several of the variables reserved by the shell are used in your .profile. You can display the current value for any shell variable by entering the following command:

   echo $variable_name
Four of the most basic of these variables are discussed next.

HOME
This variable gives the pathname of your login directory. Use the cd command to go to your login directory and type:
pwd

What was the system response? Now type:

   echo $HOME
Was the system response the same as the response to pwd?

$HOME is the default argument for the cd command. If you do not specify a directory, cd will move you to $HOME.


LANG
For many commands, this variable gives the language (such as French, German, and so on) in which messages from the system are displayed on your screen. It also specifies the language and cultural conventions the commands will use to process and sort characters, display the date and time, and interpret numeric and monetary values. The default language is English. If you prefer to work in another language, and if your system supports non-English usage, you can specify the desired language with this variable by assigning an appropriate value to it. For example, for German usage, you might enter
   LANG=de1[utsche]
Ask your system administrator which languages are available on your computer, and what values you must assign to LANG to access them. Not all system commands support non-English usage. Check intro(1) for the ones that do. For details of LANG usage, see environ(5).

PATH
This variable gives the search path for finding and executing commands. To see the current values for your PATH variable type:
   echo $PATH
The system will respond with your current PATH value.
   $ echo $PATH
   :/mylogin/bin:/bin:/usr/bin
   $
The colon ( ``:'' ) is a delimiter between pathnames in the string assigned to the $PATH variable. When nothing is specified before a ``:'', the current directory is understood. Notice how, in the last example, the system looks for commands in the current directory first, then in /mylogin/bin, then in /bin, and finally in /usr/bin.

If you are working on a project with several other people, you may want to set up a group bin, a directory of special shell programs used only by your project members. The path might be named /project1/bin. Edit your .profile, and add :/project1/bin to the end of your PATH, as in the next example.

PATH="$PATH:/project1/bin"

TERM
This variable tells the shell what kind of terminal you are using. To assign a value to it, you must execute the following three commands in this order:
   TERM=terminal_name
   export TERM
   tput init
The first two lines, together, are necessary to tell the computer what type of terminal you are using. The last line, containing the tput command, tells the terminal that the computer is expecting to communicate with the type of terminal specified in the TERM variable. Therefore, this command must always be entered after the variable has been exported.

If you do not want to specify the TERM variable each time you log in, add these three command lines to your .profile; they will be executed automatically whenever you log in.

If you log in on more than one type of terminal, it would also be useful to have your set.term command in your .profile.


PS1
This variable sets the primary shell prompt string (the default is the ``$'' sign). You can change your prompt by changing the PS1 variable in your .profile.

Try the following example. Note that to use a multi-word prompt, you must enclose the phrase in quotes. Type the following variable assignment in your .profile.

   PS1="Your command is my wish"
Now execute your .profile (with the . command) and watch for your new prompt sign.
   $ . .profile
   Your command is my wish
The ``$'' sign is gone forever, or at least until you delete the PS1 variable from your .profile.

Next topic: Shell programming exercises
Previous topic: Setting terminal options

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004