Computing Services

Classroom Services & Room Scheduling Unit

Web Services

E-Learning & Instructional Technology

Distance Education

Related Sites

Accessibility Statement. Privacy Statement.

symbol for authentication required denotes that authentication is required.

The UNIX Environment

What are environment variables?

  • The UNIX shell (csh or tcsh) is the program which processes commands entered at the command prompt (%).
  • The shell uses key = value pairs called environment variables to provide information to scripts and other programs.
  • In a script or the .cshrc file, the name of the environment variable without a preceeding dollar sign ($) represents the key (e.g. PRINTER). This syntax is usually used when a program is modifying the variable. E.g.
        setenv OURCELL sph.umich.edu
    or
        set OURCELL=sph.umich.edu
    
    The name written with a preceeding dollar sign (e.g. $PRINTER) represents the value. This form is used when reading or comparing the variable. E.g.
        if ( $OURCELL == "sph.umich.edu" ) then ...
    or
        setenv SOMEVAR "$SOMEVAR plus some new stuff"
    

Changing the environment

  • The user can view and change these variables with the set and setenv commands (see example syntax above; run the command, man setenv, to find information on the differences between set and setenv). Entering either of these commands without any arguments will display all shell and environment variables at once. See Figure 7.
  • SPH users will want to set the PRINTER variable by adding a line to their .cshrc file. E.g. the line,
        setenv PRINTER student_lp
    
    added to a user's ~/.cshrc file to set the default printer to the printer in M4048A.
  • Group or personal directories which contain frequently used programs can be appended to the PATH. For example, to add the directory /group/research/bin to the PATH, add the following line to the ~/.cshrc file:
        set path=($path /group/research/bin)
    
    This sets the value of path PATH to whatever it currently happens to be plus /group/research/bin. See the special note on PATH below.

What is the PATH environment variable?

  • The PATH variable contains a list of directories.
  • When a user enters a program name that doesn't begin with a directory name at the command prompt (e.g. ls), the shell searches for this program in each directory listed in PATH. When a user enters a command that begins with a directory name (e.g. /usr/sph/bin/ls or ~/scripts/batch), the PATH directories are not searched for the program.
  • The path variable which is controlled by the set command and the PATH variable which is controlled by the setenv command are treated by the system as one and the same. When one is changed, the shell will change the other accordingly. This is not true for most other variables changed with set or setenv.
  • In SPH, the "." directory which represents the current directory is included in the PATH. This permits the running of programs in the current directory without having to specify the directory in front of the filename even though the current directory may not be in the PATH.

Common problems

  • A user overwrites the PATH as set by the system with an incorrect value and then has trouble running programs. E.g. putting the following line in the ~/.cshrc file,
        set path=(/group/mygroup/bin /user/w/who/scripts)
    
    sets the path to point to the some custom directories but also wipes out whatever was previously stored in path. The user will find that other UNIX commands (e.g. ls) no longer work because their directories are no longer in the path. The correct way to set the path is to substitute its current value (represented by the notation, $path) into the command which sets the new path. For example,
       set path=($path /group/mygroup/bin /user/w/who/scripts)
    
  • The closing double-quote (") is left off when setting a variable in the .cshrc file. E.g.
        setenv MYVAR "This is the value
    
    This results in the message Unmatched " and the rest of the .cshrc file is not properly processed.

  • For more information, see http://www.sph.umich.edu/computing/unix/concepts.html.


    Figure 7: A sample user environment as displayed by the setenv command

    PATH=/usr/local/bin:/usr/sph/bin:/usr/bin:/usr/ucb:/usr/openwin/bin:/usr/sbin
    TZ=US/Eastern
    DISPLAY=localhost:0.0
    TERM=vs100
    SHELL=/usr/sph/bin/tcsh
    HZ=100
    HOME=/afs/sph.umich.edu/user/a/alfredo
    USER=alfredo
    LOGNAME=alfredo
    MAIL=/usr/mail/alfredo
    PASSWORD_EXPIRES=255
    HOSTTYPE=sun4
    VENDOR=sun
    OSTYPE=solaris
    MACHTYPE=sparc
    SHLVL=1
    PWD=/afs/sph.umich.edu/user/a/alfredo
    GROUP=other
    HOST=srvr1
    LD_LIBRARY_PATH=/usr/lib:/usr/sph/X11/lib:/usr/sph/lib:/usr/dt/lib:/usr/sph/devp
    ro_v5n1/SUNWspro/lib:/usr/openwin/lib
    OPENWINHOME=/usr/openwin
    MANPATH=/usr/sph/man:/usr/share/man:/usr/openwin/man
    XKEYSYMDB=/usr/sph/lib/XKeysymDB
    SHOME=/usr/sph/splus-3.4
    XNLSPATH=/usr/sph/X11/lib/X11/nls
    XLOCALEDIR=/usr/sph/X11/lib/X11/locale
    TEXMF=/usr/sph/tetex/texmf
    PRINTER=6
    LSHOST=gateway
    EDITOR=vi
    TERMCAP=xterm|vs100:AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:UP=\E[%dA:
    al=\E[L:am:bs:cd=\E[J:ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:co#80:cs=\E[%i%d;%dr:c
    t=\E[3k:dc=\E[P:dl=\E[M:im=\E[4h:ei=\E[4l:mi:ho=\E[H:is=\E[r\E[m\E[2J\E[H\E[?7h\
    E[?1;3;4;6l\E[4l:rs=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l\E[4l\E<:k1=\EOP:k2=\EOQ:
    k3=\EOR:k4=\EOS:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:km:kn#4:kr=\EOC:ks=\E[?1h\E=:
    ku=\EOA:li#50:md=\E[1m:me=\E[m:mr=\E[7m:ms:nd=\E[C:pt:sc=\E7:rc=\E8:sf=\n:so=\E[
    7m:se=\E[m:sr=\EM:te=\E[2J\E[?47l\E8:ti=\E7\E[?47h:up=\E[A:us=\E[4m:ue=\E[m:xn: