System Administration Guide, Volume I

Shell Environment

A shell maintains an environment that includes a set of variables defined by the login program, the system initialization file, and the user initialization files. In addition, some variables are defined by default. A shell can have two types of variables:

In the C shell, you use the lowercase names with the set command to set shell variables and use uppercase names with the setenv command to set environment variables. If you set a shell variable, the shell sets the corresponding environment variable and vice versa. For example, if you update the path shell variable with a new path, the shell also updates the PATH environment variable with the new path.

In the Bourne and Korn shells, you use the uppercase names with the setenv command to set both shell and environment variables. You also have to use the export command to finish setting environment variables. For all shells, you generally refer to shell and environment variables by their uppercase names.

In a user initialization file, you can customize a user's shell environment by changing the values of the predefined variables or by specifying additional variables. Table 1-12 shows how to set environment variables in a user initialization file.

Table 1-12 Setting Environment Variables in a User Initialization File

If You Want to Set a User's Environment Variables for The ... 

Then Add the Following Line to the User Initialization File ... 

C shell

setenv VARIABLE value

Example:

setenv MAIL /var/mail/ripley

Bourne or Korn shell

VARIABLE=value; export VARIABLE

Example: 

MAIL=/var/mail/ripley;export MAIL

Table 1-13 describes environment and shell variables you may want to customize in a user initialization file. For more information about variables used by the different shells, see sh(1), ksh(1), or csh(1).

Table 1-13 Shell and Environment Variable Descriptions

Variable 

Description 

ARCH

Sets the user's system architecture (for example, sun4, i386). This variable can be set with ARCH = `uname -p` (in Bourne or Korn shells) or setenv ARCH `uname -p` (in C shell). There is no built-in behavior of the shell that depends on this variable. It's just a useful variable for branching within shell scripts.

CALENDAR

Sets the path to the Calendar executables. 

CDPATH (or cdpath in the C shell)

Sets a variable used by the cd command. If the target directory of the cd command is specified as a relative path name, the cd command will first look for the target directory in the current directory ("."). If the target is not found, the path names listed in the CDPATH variable are searched consecutively until the target directory is found and the directory change is completed. If the target directory is not found, the current working directory is left unmodified. For example, the CDPATH variable is set to /home/jean, and two directories exist under /home/jean: bin and rje. If you are in the /home/jean/bin directory and type cd rje, you change directories to /home/jean/rje, even though you do not specify a full path.

DESKSET

Sets the path to the DeskSetTM executables.

history

Sets history for the C shell. 

HOME (or home in the C shell)

Sets the path to the user's home directory. 

LANG

Sets the locale. 

LOGNAME

Defines the name of the user currently logged in. The default value of LOGNAME is automatically set by the login program to the user name specified in the passwd file. You should only need to refer to (not reset) this variable.

LPDEST

Sets the user's default printer. 

MAIL

Sets the path to the user's mailbox. 

MANPATH

Sets the hierarchies of man pages available. 

MANSECTS

Sets the hierarchies of man pages available. 

OPENWINHOME

Sets the path to the OpenWindows subsystem. 

PATH (or path in the C shell)

Lists, in order, the directories that the shell searches to find the program to run when the user types a command. If the directory is not in the search path, users must type the complete path name of a command.  

The default PATH is automatically defined and set as specified in .profile (Bourne or Korn shell) or .cshrc (C shell) as part of the login process.

 

The order of the search path is important. When identical commands exist in different locations, the first command found with that name is used. For example, suppose that PATH is defined (in Bourne and Korn shell syntax) as PATH=/bin:/usr/bin:/usr/sbin:$HOME/bin and a file named sample resides in both /usr/bin and /home/jean/bin. If the user types the command sample without specifying its full path name, the version found in /usr/bin is used.

prompt

Defines the shell prompt for the C shell. 

PS1

Defines the shell prompt for the Bourne or Korn shell. 

SHELL (or shell in the C shell)

Sets the default shell used by make, vi, and other tools.

TERMINFO

Specifies the path name for an unsupported terminal that has been added to the terminfo file. Use the TERMINFO variable in /etc/profile or /etc/.login.

 

When the TERMINFO environment variable is set, the system first checks the TERMINFO path defined by the user. If it does not find a definition for a terminal in the TERMINFO directory defined by the user, it searches the default directory, /usr/share/lib/terminfo, for a definition. If it does not find a definition in either location, the terminal is identified as "dumb."

TERM (or term in the C shell)

Defines the terminal. This variable should be reset in /etc/profile or /etc/.login. When the user invokes an editor, the system looks for a file with the same name as the definition of this environment variable. The system searches the directory referenced by TERMINFO to determine the terminal characteristics.

TZ

Sets the time zone, which is used to display dates, for example, in the ls -l command. If TZ is not set in the user's environment, the system setting is used; otherwise, Greenwich Mean Time is used.