.bashrc vs. .bash_profile

Ed Cogburn edcogburn at hotpop.com
Fri Jul 22 18:42:26 UTC 2005


Matthew S-H wrote:

> 
> On Jul 15, 2005, at 5:30 AM, Ed Cogburn wrote:
> 
>> 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
>> both.  :)
>>
>> 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...  :)
> 
> Just an alternative that I am doing now that simplifies things even
> more:
> 
> sudo ln -s /etc/bash_profile /etc/bashrc
> ln -s ~/.bash_profile ~/.bashrc
> 
> That simplifies things even more, I think.


That'll work too. :)

The reason I don't do this is that I don't have a "profile" file in etc at
all.  I have a common rc file there which is loaded by both the login and
rc files in my user's home directory.  So in a way there is only one file,
the one all the user files point to.  Yeah, symlinks will work fine too,
but when you think about it there's not much difference between a symlink
(that stores the name of the file it points to) and a text file with only
one line "source /etc/bashrc", and you can use a period instead of the word
'source' to make the line even smaller if you wish (all of these files
we're talking about are "sourced", not executed, so there is no need for
the "#!/bin/sh" line).  The difference (too me) is that its easier to
change a text file (especially if you rely on file managers where a text
editor is only a single keystroke away), than deleting and recreating a
symlink, and then what do you do when you just want to test something
temporarily?


> If I am wrong about this working, I'd appreciate it if someone would
> tell me before I F--K my system up.


Pay no heed to those who tell you how you're "supposed" to do things, or
what the "right" way is, just do whatever works best for you, although
asking how others do things doesn't hurt.  It is that freedom of choice
that brought me to Linux in the first place and its what keeps me, despite
zealots who seem to find all sorts of strange ideas to become zealous over. 
What?  You use .bash_login instead of .bash_profile?  Why you godless
heretic!!!  :)






More information about the ubuntu-users mailing list