LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-29-2004, 03:48 PM   #1
MDesigner
Member
 
Registered: Jun 2004
Distribution: openSUSE 10.2
Posts: 69

Rep: Reputation: 15
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?
 
Old 06-29-2004, 04:07 PM   #2
zorba4
Member
 
Registered: Feb 2004
Location: Paris
Posts: 398

Rep: Reputation: 31
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.
 
Old 06-29-2004, 04:20 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
Old 06-29-2004, 04:29 PM   #4
MDesigner
Member
 
Registered: Jun 2004
Distribution: openSUSE 10.2
Posts: 69

Original Poster
Rep: Reputation: 15
Ahh.. duh! It's .bash_profile not .bashrc Works now..

Last edited by MDesigner; 06-29-2004 at 04:32 PM.
 
Old 06-29-2004, 05:49 PM   #5
MDesigner
Member
 
Registered: Jun 2004
Distribution: openSUSE 10.2
Posts: 69

Original Poster
Rep: Reputation: 15
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?
 
Old 06-29-2004, 05:51 PM   #6
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
no scripts get executed when u open a term
they execute when you log in
 
Old 06-29-2004, 05:54 PM   #7
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
Old 06-29-2004, 07:28 PM   #8
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Quote:
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.
 
Old 06-29-2004, 08:55 PM   #9
darthtux
Senior Member
 
Registered: Dec 2001
Location: 35.7480° N, 95.3690° W
Distribution: Debian, Gentoo, Red Hat, Solaris
Posts: 2,070

Rep: Reputation: 47
All I have in my ~/.bash_profile is
Code:
source.bashrc
~/.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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/etc/profile V.S. /etc/bashrc Takayuki Linux - General 12 05-17-2011 11:25 PM
/etc/profile vs /etc/bashrc maybbach Linux - Newbie 6 04-22-2005 09:50 AM
/etc/profile vs. /etc/bash.bashrc jbrashear Debian 3 03-11-2004 03:49 PM
RH9 bashrc and profile magnusprime Red Hat 5 09-01-2003 05:32 PM
Where's my .bashrc or .profile t1mc00per Linux - Software 6 03-03-2003 10:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration