Sunday, February 19, 2012

.bash_profile vs .bashrc

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

If you’ve already logged into your machine and open a new terminal window, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.

Most of the time you don’t want to maintain two separate config files for login and non-login shells. You can fix this by sourcing .bashrc from your .bash_profile file, then putting PATH and common settings in .bashrc. To do this, add the following lines to .bash_profile:

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

Now when you login to your machine from a console .bashrc will be called.

References

No comments:

Post a Comment