Shell Configuration Files

This week I will discuss shell configuration files and their uses.

Shell configuration files are executed automatically when you log in and

out of a shell. They initialize and configure a shell upon login and

perform cleanup operations upon logout.


BASH defines three configurations files: .bash_profile, .bashrc, and

.bash_logout. .bash_profile contains initialization commands that set

environment variables, a shell's prompt and so on. The .bashrc contains

commands that configure the shell, define command aliases and set

command shell options. .bash_profile is executed automatically when a

user logs into a shell, along with .bashrc. The .bash_logout file is

executed when the user logs out of a shell. .bash_logout contains

cleanup operations and other commands that you want the shell to execute

whenever a user logs out of a shell. For example, it can include

commands that clear the screen and print a farewell message. Unlike the

.bash_profile file, which is created automatically when you open a new

account, you have to create the .bash_logout by yourself using a text

editor such as vi, emacs, etc.

In the following example, the .bash_logout file contains commands that

clear the screen and print a reminder to the user to take her diskette

from the disk drive:


echo "don't forget to remove your homework exercises diskette from the

diskette drive!"

Other Shells

Other shells have similar configuration files, albeit with different

names. Thus, instead of the BASH .bash_profile, .bashrc, and

.bash_logout configuration files, TCSH uses the .login, .tcshrc and

.logout configuration files, respectively. Likewise, Z-shell uses the

files .zshenv, .zprofile, and .zlogin for initialization, .zshrc as a

configuration file equivalent to .bashrc, and .zlogout as the equivalent

of .bash_logout. The PDKSH shell uses the .profile and .kshrc files for

initialization and shell configuration, respectively.

A correction

In last week's newsletter, the meaning of the arguments +o and -o got

inverted. The +o argument actually turns a feature off whereas -o turns

it on. Thanks to all the readers who have drawn my attention to this


ITWorld DealPost: The best in tech deals and discounts.
Shop Tech Products at Amazon