.bashrc vs. .bash_profile
edcogburn at hotpop.com
Fri Jul 15 09:30:03 UTC 2005
Russell Cook wrote:
> On Fri, 2005-07-15 at 07:22 +0200, Dennis Kaarsemaker wrote:
>> On vr, 2005-07-15 at 01:05 -0400, Matthew S-H wrote:
>> > What is the difference? Under what situations does it read one over
>> > the other?
>> .bash_profile is sourced for login shells (where you need to enter a
>> password) and .bashrc for the rest. So .bash_profile should contain
>> thing only to be done once per session and .bashrc should contain things
>> to be done for every terminal you open.
> Hi Dennis,
> that makes sense, but for noobies, how do we tell what needs to be run
> for ever terminal. For instance the path extension statement I was
> looking at. Is the path global for that login, or only that shell?
If you're lazy, and don't want to waste time trying to figure this all out
(its because of maintaining backwards compatibility with 30+ years of
Bourne shells that "this" has gotten so complicated - given the speed of
machines today there is no reason to maintain this distinction we still
have), and don't care if your machine wastes a few cycles and a small
fraction of a second when starting up (how big a fraction depends on what
stuff you're doing at startup of a shell), just run the same thing for
Have ".bash_profile" (also known as ".bash_login") for login shells, and
".bashrc" for all other shells just source the same file, like say
".bash_startup", and have the 2 previous files just have "source
~/.bash_startup" as the only line in them. Then put whatever settings you
need in that one file, and "forget" about the other two.
There are variations on this, whatever suits your preferences. I have a
single file in /etc/ that is sourced by both of those files above. Others
put most of their settings in .bashrc, and have the login shell source that
as the last command in its .bash_login, etc. etc.
About the only thing that really makes sense being in one of .bash_login
or .bash_profile, but not in .bashrc are commands that affect the display
of the command line prompt. However, if you're using midnight commander,
it unfortunately uses a non-login shell for the shell line it shows at the
bottom, even though its used just like a login shell, so for that reason
and for laziness, I just have both "types" of shells set themselves up
exactly the same way. Seems to work fine, haven't seen any smoke coming
from the case yet... :)
More information about the ubuntu-users