Why does /etc/profile take precedence over my .bashrc file?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why does /etc/profile take precedence over my .bashrc file?
I noticed that whatever is in /etc/profile seems to take precedence over stuff in my ~/.bashrc file. How do I make it so the /etc/profile stuff is executed first... and then my .bashrc?
Nope, MDesigner, not sure you are right.
Simply try it. Put "myname=John" in your .bashrc, then logout, login, and echo $myname.
Several things you cannot change in .bashrc, but most of them you are free.
I read somewhere that ~/.bashrc is not automatically read when you start up a bash shell. /etc/profile and ~/.bash_profile are the only files automatically included. I'll have to go find where I read that. Anyway, if that is the case, then you need to explicitly tell bash to include your ~/.bashrc. You can do that easily enough by adding this to your ~/.bash_profile:
Code:
if [ -e ${HOME}/.bashrc ] ; then
source ${HOME}/.bashrc
fi
If your system has /etc/bashrc, then you can probably see an example of the code above in /etc/profile manually including the contents of /etc/bashrc.
Just as a side note, a single dot ('.') is an alias for the source command, and it might be used in /etc/profile.
Now here's something weird.. when I'm on the Linux machine physically, logged into X, and start up a gnome terminal, the .bash_profile does not get executed. Why is that? Which scripts get executed when I open a terminal?
Try logging out of X and logging back in. I don't know for sure, but I believe I ran into this before. I made a change to one of the files and it refused to "take" until I fully logged out.
The only rational explanation I can come up with is that once you log in, maybe X caches your configuration files in memory rather than reading them from the disk each time you open a new terminal.
I could be completely wrong though.... it's been known to happen.
<edit>
Errr... I think maybe scuz and I are talking about the same thing... again, could be wrong
</edit>
Last edited by Dark_Helmet; 06-29-2004 at 05:56 PM.
Originally posted by scuzzman no scripts get executed when u open a term
they execute when you log in
Not entirely true. Login scripts (profile, bash_profile) are executed when you log in, but bashrc is executed upon opening a new bash shell, such as an X terminal.
~/.bash_profile is ONLY for login shells. ~/.bashrc is for non-login shells. The above code makes ~/.bash_profile read all the settings in ~/.bashrc. Then I put all my settings in ~/.bashrc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.