.bashrc vs. .bash_profile

Matthew S-H mathbymath at aol.com
Wed Jul 20 18:58:08 UTC 2005


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.
Now, you don't even have to remember which is the original.
Also, if you wan't, you could make hard links instead of symbolic  
links by removing the "-s" option.

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



~Matt




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050720/8c42f525/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2149 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050720/8c42f525/attachment.bin>


More information about the ubuntu-users mailing list