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



Holds full pathname of BASH command


Displays the current BASH version number


Groups that the user belongs to


Number of the current command in the history list


Pathname for user's home directory


The host name


Displays the type of machine the host runs on


Previous working directory


Operating system in use


List of pathnames for directories searched for executable commands


Process ID for shell's parent shell


User's working directory


Generates random number when referenced


Current shell level, number of shells invoked


User ID of the current user

Table 9-3 Shell Variables, Set by the Shell

Shell Variables



Displays the current BASH version number


Search path for the cd command


Initialization commands for Ex/Vi editor


Editor used by the history fc command.


Groups that the user belongs to


The pathname of the history file


Number of commands allowed for history


Size of the history file in lines


Number of the current command in the history list


Pathname for user's home directory


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


Interfield delimiter symbol


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



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


The pathname location for the KDE desktop


Login name


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


Interval for checking for received mail


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


Linux platforms, like i686, x86_64, or ppc


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


The pathname of the history file


Primary shell prompt


Secondary shell prompt


Location of the Qt library (used for KDE)


Pathname of program for type of shell you are using


Terminal type


Time that the shell remains active awaiting input


User name


Real user ID (numeric)


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.

0 0

Post a comment