Configuring the Shell

There are two sets of configuration files for any shell. Some are system-wide; in other words, they affect all users on your Linux computer. Others are user specific and are stored in a user s home directory.

Depending on your distribution, there are two basic system-wide configuration files for bash: /etc/bashrc and /etc/profile . Each of these files contains two different kinds of variables : shell variables , which remain constant only within a specific shell such as bash, and environment variables , which stay with you even if you change shells .

In other words, shell variables are local, and environment variables are global.

Shell Variables

The default Red Hat Linux /etc/bashrc configuration file, shown in Figure 8.2, sets two basic shell variables: a default value for umask , and the prompt that you see with the cursor at the command-line interface.

click to expand
Figure 8.2: /etc/bashrc      

These configuration files work with customizable files in each user s home directory. By default, they include .bash_history , .bash_logout , .bash_profile , and .bashrc . While you can customize each of these files, they contain several defaults. The periods in front of each of these files hides them from normal searches. You can view hidden files with the ls -a command.

.bash_history Includes a history of your previous bash commands. Some administrators do not like this file, because crackers may be able to get clues to your system from the commands that you used. You can discontinue this process by adding HISTFILESIZE=0 to your .bash_profile file as shown in Figure 8.3.

click to expand
Figure 8.3: You can find a lot of previous commands in your .bash_history .

.bash_logout Sets commands for when you exit a shell. By default, this includes the clear command, which wipes out your previous commands from the current terminal window. A sample of the simple default .bash_logout file is shown in Figure 8.4.

click to expand
Figure 8.4: A home directory .bash_logout

.bash_profile Calls the .bashrc file for more configuration data. Adds the ~/bin directory to your PATH as shown in Figure 8.5 . If you add the HISTFILESIZE=0 variable, remember to add it to the export list in this file.

click to expand
Figure 8.5: A home directory .bash_profile

.bashrc Calls the /etc/bashrc file for basic configuration data. For the root user, this file adds aliases for the rm , mv , and cp commands to help prevent accidental deletion of a file, as shown in Figure 8.6.

click to expand
Figure 8.6: A home directory .bashrc

When you run the export command on a shell variable, you re essentially making it into a global, or an environment, variable. Global variables are also available to your programs.


Remember, if you don t document your variables in the .bash files in your home directory, your setup will revert to the original configuration the next time you log into Linux.

Environment Variables

There are a large number of default environment variables, which you can review with the env command. Some are set through /etc/profile . These variables include colors for filenames, settings for the secure shell, and default terminal and display variables. We ve listed some of the standard environment variables in Table 8.2.

Table 8.2: Other Major Default Environment Variables




The default shell.


The default language.


Environment variables for the bash shell, normally in ~/.bashrc .


The console used for the X-Window. DISPLAY=:0 corresponds to console F7; DISPLAY=:1 corresponds to F8; DISPLAY=server:0 sends GUI applications to a remote computer.


The default terminal in a GUI, normally gnome-terminal .


Linux automatically searches through all directories in your path for a desired command, in the order shown from the output to the echo $PATH command. /etc/profile automatically adds several directories to the root user s PATH .


Automatically set to the username of the currently logged-in user.


Normally set to $USER .


Set to the standard mail directory for a specific $USER .


Set to the output of the /bin/hostname command.


Sets the number of commands remembered by the history command.


Sets defaults for keyboard mapping. See /etc/inputrc for details.

It s easy to reset environment variables. One of the most important of these is the PATH . Say you ve added a number of scripts to the /opt/data/db/programs directory and do not want to cite the full directory path every time you want to run one of these programs. The following command adds this directory to your PATH :

 # PATH=$PATH:/opt/data/db/programs 

Now if you want to run a program such as /opt/data/db/programs/script1 , all you need to do is type script1 and press Enter. But remember, to make the change permanent you ll need to revise the .bash_profile configuration file in your home directory to reflect the change to your PATH . To find the current directories in your PATH , run the echo $PATH command.


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220 © 2008-2017.
If you may any questions please contact us: