Saturday, July 19, 2008

Linux initialization files: .bash_profile and .bashrc

As a Linux or Cygwin (Linux emulation for Windows) new, would you wonder what really happen when you execute the shell (e.g., double click on the Cygwin icon)? In the old day, Windows always invokes a file called "autoexec.bat". This file contains a bunch of thing the the window will do at the boot-up such as setting path or invoke other programs (e.g., anti-virus).

In your home directory, there are two files, ".bash_profile" and ".bashrc", which are the initialization file in the Linux. When you open a shell, they are automatically executed as a shell initialization.The path setting is contained in these files.

The difference? According to [Josh Staiger],

- ".bash_profile" is invoked for a log-in session. Log-in? Yeah, log-in. It means anything that you usually need to provide user name and password such as log-in physically at the boot-up or using ssh

- ".bashrc" is invoked for a non-log-in session. For example, when you have already log-in to a graphical environment such as KDE. All you have to do is to click on a terminal icon and you don't have to provide username/password to open a shell.

In fact, you can see in the file ".bash_profile" the following

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi


which basically invokes ".bashrc" if it exists.

For the Cygwin environment, you can add your own initialization in either ".bashrc" or ".bash_profile". Wanna try? Add the following lines into the files and restart the shell.

- Add to ".bashrc"


echo Add2.bashrc


- Add to ".bash_profile"

echo Add2.bash_profile

PATH=${PATH}:
export =


ENJOY...

No comments: