Configuring Your Shell with Shell Parameters

When you log in to your account, the system generates a shell for you. This shell is referred to as either your login shell or your user shell. When you execute scripts, you are generating subshells of your user shell. You can define variables within your user shell, and you can also define environment variables that can be referenced by any subshells you generate.

When you log in, Linux will set certain parameters for your login shell. These parameters can take the form of variables or features. See the previous section "Controlling Shell Operations" for a description of how to set features. Linux reserves a predefined set of variables for shell and system use. These are assigned system values, in effect, setting parameters. Linux sets up parameter shell variables you can use to configure your user shell. Many of these parameter shell variables are defined by the system when you log in. Some parameter shell variables are set by the shell automatically, and others are set by initialization scripts, described later. Certain shell variables are set directly by the shell, and others are simply used by it. Many of these other variables are application specific, used for such tasks as mail, history, or editing. Functionally, it may be better to think of these as system-level variables, as they are used to configure your entire system, setting values such as the location of executable commands on your system, or the number of history commands allowable. See Table 9-3 for a list of those shell variables set by the shell for shell-specific tasks; Table 9-4 lists those used by the shell for supporting other applications.

finished execution, its shell terminates and you return to the shell from which it was executed. In this sense, you can have many shells, each nested within the other. Variables you define within a shell are local to it. If you define a variable in a shell script, then, when the script is run, the variable is defined with that script's shell and is local to it. No other shell can reference that variable. In a sense, the variable is hidden within its shell.

You can define environment variables in all types of shells, including the BASH shell, the Z shell, and the TCSH shell. The strategy used to implement environment variables in the BASH shell, however, is different from that of the TCSH shell. In the BASH shell, environment variables are exported. That is to say, a copy of an environment variable is made in each subshell. For example, if the EDITOR variable is exported, a copy is automatically defined in each subshell for you. In the TCSH shell, on the other hand, an environment variable is defined only once and can be directly referenced by any subshell.

In the BASH shell, an environment variable can be thought of as a regular variable with added capabilities. To make an environment variable, you apply the export command to a variable you have already defined. The export command instructs the system to define a copy of that variable for each new shell generated. Each new shell will have its own copy of the environment variable. This process is called exporting variables. To think of exported environment variables as global variables is a mistake. A new shell can never reference a variable outside of itself. Instead, a copy of the variable with its value is generated for the new shell.

Shell Variables

Description

BASH

Holds full pathname of BASH command

BASH_VERSION

Displays the current BASH version number

GROUPS

Groups that the user belongs to

HISTCMD

Number of the current command in the history list

HOME

Pathname for user's home directory

HOSTNAME

The host name

HOSTTYPE

Displays the type of machine the host runs on

OLDPWD

Previous working directory

OSTYPE

Operating system in use

PATH

List of pathnames for directories searched for executable commands

PPID

Process ID for shell's parent shell

PWD

User's working directory

RANDOM

Generates random number when referenced

SHLVL

Current shell level, number of shells invoked

UID

User ID of the current user

Table 9-3 Shell Variables, Set by the Shell

Shell Variables

Description

BASH_VERSION

Displays the current BASH version number

CDPATH

Search path for the cd command

EXINIT

Initialization commands for Ex/Vi editor

FCEDIT

Editor used by the history fc command.

GROUPS

Groups that the user belongs to

HISTFILE

The pathname of the history file

HISTSIZE

Number of commands allowed for history

HISTFILESIZE

Size of the history file in lines

HISTCMD

Number of the current command in the history list

HOME

Pathname for user's home directory

HOSTFILE

Sets the name of the hosts file, if other than /etc/hosts

IFS

Interfield delimiter symbol

IGNOREEOF

If not set, EOF character will close the shell. Can be set to the number of EOF characters to ignore before accepting one to close the shell (default is 10)

Table 9-4 System Environment Variables Used by the Shell (continued)

Shell Variables

Description

INPUTRC

Set the inputrc configuration file for Readline (command line). Default is current directory, .inputrc. Red Hat and Fedora set this to /etc/inputrc

KDEDIR

The pathname location for the KDE desktop

LOGNAME

Login name

MAIL

Name of specific mail file checked by Mail utility for received messages, if MAILPATH is not set

MAILCHECK

Interval for checking for received mail

MAILPATH

List of mail files to be checked by Mail for received messages

HOSTTYPE

Linux platforms, like i686, x86_64, or ppc

PROMPT_COMMAND

Command to be executed before each prompt, integrating the result as part of the prompt

HISTFILE

The pathname of the history file

PS1

Primary shell prompt

PS2

Secondary shell prompt

QTDIR

Location of the Qt library (used for KDE)

SHELL

Pathname of program for type of shell you are using

TERM

Terminal type

TMOUT

Time that the shell remains active awaiting input

USER

User name

UID

Real user ID (numeric)

EUID

Effective user ID (numeric). This is usually the same as the UID but can be different when the user changes IDs, as with the su command, which allows a user to become an effective root user.

Table 9-4 System Environment Variables Used by the Shell

Table 9-4 System Environment Variables Used by the Shell

A reserved set of keywords is used for the names of these system variables. You should not use these keywords as the names of any of your own variable names. The system shell variables are all specified in uppercase letters, making them easy to identify. Shell feature variables are in lowercase letters. For example, the keyword HOME is used by the system to define the HOME variable. HOME is a special environment variable that holds the pathname of the user's home directory. On the other hand, the keyword noclobber is used to set the noclobber feature on or off.