Tutorial on Figuring Out Your Server: Environmental Variables

Files, Disk Usage
This tutorial has examples for four versions of UNIX: Linux, Oracle’s Solaris, Apple’s Macintosh OS X and IBM’s AIX
Environmental Variables: Your Configuration
Your user ID impacts what you can do in two important ways: permissions and environmental variables.

Understanding your environmental variables is critical to understanding your application. Often, an application is run by a service account. Once you’re logged in as that service account, the command env will often give you important settings used by your application, such as where your application’s binaries are located, where log files are written, the location of key configuration files, and so on. Your vendor or development team may provide you with a list of environmental variables.

The environmental variable $SHELL indicates the shell you are using.

The shell is the command line interface with the OS. Most support staff will end up learning the shell preferred by senior technical staff or specified by a software vendor.
echo $SHELL
env | grep SHELL
printenv | grep SHELL

The most commonly used shells are:
• Bourne Shell (/bin/sh or /sbin/sh): most frequently used for the root (administrator account) on Solaris servers.
• C shell (/bin/csh): Not as commonly used as in the past.
• Korn shell (/bin/ksh): Was very popular because it has many excellent features and uses all Bourne shell commands as well.
• Bourne-Again Shell, popularly known as BASH (/bin/bash): Default shell for LINUX and very popular among Linux users. Like ksh, bash is backwards compatible with sh so that sh commands and scripts will work with bash.

Switching between csh and other shells may cause a little confusion among new UNIX users. However, the most commonly used commands are the same in all the shells.

The environmental variables are set when you log in by reading the initialization files. If your default shell is sh, ksh or bash the initialization files are:
• /etc/profile (system-wide settings)
• $HOME/.profile (user settings)
• $HOME/.bash_profile (bash only)
• $HOME/.bash_login (bash only)

If your default shell is csh, the following files are read:
• /etc/profile
• $HOME/.cshrc
• /etc/.login

Note that each of the initialization files can also source other configuration files, i.e., get settings from the other files. For example, an application-specific configuration file can be sourced by all
users of that application. If those settings need to be changed, someone only needs to change that one shared configuration file.

Displaying Environmental Variables
You can display the values of individual environmental variables with the echo command. For example, to determine your shell:
echo $SHELL

You can also display all your environmental variables with the env and printenv commands.
env | more
printenv | more

You can pipe output from env or printenv to grep as an alternative to echo to determine a specific environmental variable. For example, the following commands will display $HOME (the location of your home directory):
echo $HOME
env | grep HOME
printenv | grep HOME

Note that the following two commands will both put you in the home directory:
cd $HOME

Some people prefer to determine the home directory by these two steps:

Other Important Environmental Variables
$LOGNAME: your login name
echo $ LOGNAME
env | grep LOGNAME
printenv | grep LOGNAME

$MAIL: file where your incoming mail is stored
echo $ MAIL
env | grep MAIL
printenv | grep MAIL

$PATH: list of directories search whenever you enter a command
echo $PATH
env | grep PATH
printenv | grep PATH

$PWD: You probably already know this one, Present Working Directory. When you first log in, your working directory will be your home directory. The command
will give you the same information as echo $PWD.
echo $PWD
env | grep PWD
printenv | grep PWD

$TERM: terminal emulation being used. The most common value is vt102
echo $TERM
env | grep TERM
printenv | grep TERM

$TZ: time zone used by your system. Not always set.
echo $TZ
env | grep TZ
printenv | grep TZ

Applications and Environmental Variables
The application you support probably runs as a specific user. In order to run the different maintenance commands, you may have to log in as that user or another specific user. This is often called an “admin account”. Part of the reason your application will run only as a certain user is at least partially due to the environmental variables used by this user ID. You may find by examining the output from env that there are some application-specific environmental variables such as the application’s root directory, location of binaries, location of logs or other configurable settings.

If you are logged in to an admin account, try to find some application-specific environmental variables with one of these commands:
printenv | more
env | more

Lets say you support an application called, just to pick three letters at random, FNX. You may see environmental variables like these:
paloalto [1]> env | grep -i fnx
Suggestions for Future Learning
Further information on how environmental variables can be used can be found in  UNIX For Application Support Staff Chapter  3, Applications.

Tutorial Contents

Name Service queries with DNS and NIS

What Is My Server’s Configuration ?

Hardware Information : CPU and Memory

Environmental Variables : Your Configuration

Disk Usage  and Listing Directory Contents

Who Else  is Logged in?

Files, Disk Usage