Thursday, October 9, 2008

bashrc vs. bash_profile

mikeshn

bashrc, bash_profile These two files looks pretty similar. What is the purpose of these files ?



bogdan

I got these lines from bash manual.

~/.bash_profile
The personal initialization file, executed for login shells

~/.bashrc
The individual per-interactive-shell startup file

To be more clear:

.bashrc will be executed everytime you open the terminal from within Gnome, as you are not making a login.

.bash_profile is executed after login to a terminal. In the case of desktop systems, if I am not mistaking, this file is executed after the graphical login, just once. If you were to boot without graphical mode, after you were presented with bash login prompt, this file would be executed after successful login.


geirha
No, opening a terminal in gnome will also give you a login shell. .bash_profile is read when you open a terminal, log in at the console or specifically start a loginshell with Code:

bash --login

.bashrc is read for non-login shells. Typically that means when you run bash-scripts; it spawns a new bash process to run the script, but it only reads .bashrc.

The .bash_profile provided to you with ubuntu, will run .bashrc too, so .bashrc is "always" read.


kpkeerthi

The commands in .bash_profile will be run every time the user logs in.
The commands in .bashrc will be run everytime you open bash shell (the terminal). .bash_profile will not be run in this case.

* Usually .bash_profile internally invokes .bashrc. So .bashrc will also be run once upon login.



No comments:

Post a Comment