next up previous contents index
Next: A Summary of Up: Environment Variables Previous: Setting Environment Variables

Getting Values of Environment Variables

The contents of environment variables can be made visible with the echo command. To get the value, the name of the environment variable must be preceeded by a $-sign:

 
               		  echo $PRINTER

513-pub

The value for PRINTER is shown. If you forget the $-sign, the character string is printed and not its value:
 
               		  echo PRINTER

PRINTER

Again you should keep in mind that Unix is case sensitive. This means that environment variables such as printer, Printer and PRINTER are all different.

A More Advanced Example

For example, if you want to have your current host name and current working directory named MyEnv, using the Bourne Shell you can proceed as follows:

 
               		  NODE=`hostname`; export NODE

MyEnv=$NODE:$PWD; export MyEnv

echo 'My Environment: $MyEnv'

My environment: rzri6f:/u/goeri

With the first statement, a new global variable NODE is defined. NODE gets the output of the command hostname as value, which is achieved by enclosing the command name in single backquotes. Then the values of NODE and of the environment variable PWD, which is already provided by the system and contains always the current working directory, are put together in MyEnv. Finally, to control the success of this action, the contents of MyEnv is printed to your terminal window, prefixed by some text.



Alan Silverman
Wed Apr 12 16:54:02 METDST 1995