Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-04-2005, 11:31 PM
|
#1
|
|
LQ Newbie
Registered: Jan 2005
Location: Tokyo
Posts: 6
Rep:
|
/etc/profile V.S. /etc/bashrc
Hello This is first time I write in here.I am studying for LPIC level 1 right now.
But I couldn't understand the diffrence between "/etc/profile" and "/etc/bashrc.If someone could explain to me or If you have find source at the web. please let me know.
|
|
|
|
|
Click here to see the post LQ members have rated as the most helpful post in this thread.
|
01-11-2005, 10:26 PM
|
#2
|
|
Senior Member
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088
Rep:
|
From "man bash"
Quote:
When bash is invoked as an interactive login shell, or as
a non-interactive shell with the --login option, it first
reads and executes commands from the file /etc/profile, if
that file exists. After reading that file, it looks for
~/.bash_profile, ~/.bash_login, and ~/.profile, in that
order, and reads and executes commands from the first one
that exists and is readable.
|
Quote:
When an interactive shell that is not a login shell is
started, bash reads and executes commands from ~/.bashrc,
if that file exists.
|
In other words, /etc/profile is run when a user logs in. ~/.bashrc is run for other shells (Ie opening an xterm)
I hope this helps
--Ian
--Ian
|
|
|
|
01-12-2005, 03:12 AM
|
#3
|
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
/etc/profile and /etc/bashrc are similar, but traditionally have different purposes.
As IBall mentioned, the main difference is that /etc/bashrc is not automatically read in under any circumstance. The only way it gets included, is if it's referenced in your ~/.bashrc file with something like:
Code:
if [ -f /etc/bashrc ] ; then
. /etc/bashrc
fi
/etc/profile is read in automatically only if the shell is a login shell.
Aside from that, they [i]could[/] contain the exact same information, but because of that behavior, they become specialized. /etc/profile contains system/global environment variables and startup programs. Since environment variables are persistent (each process started by a shell inherits them) it's only needed to read them once. Similarly, once a startup program is launched, there is no need to start it again.
Since /etc/bashrc is included by ~/.bashrc, and read every time a shell starts up, people use it to include shell aliases and functions. Aliases and functions do not behave like environment variables; they are not passed to other processes. If you want to see an example, do this at a command prompt:
Code:
alias testecho='echo this is a test!'
cat > ~/test_script.bash << EOF
#!/bin/bash
testecho
EOF
chmod u+x ~/test_script.bash
~/.test_script.bash
Executing the script in the last line will give you a "testecho: command not found" error because aliases and functions are not passed to sub-processes. So, since ~/.bashrc isincluded with every shell (and implicitly /etc/bashrc), then people use these to set up aliases and functions so all of their shells have the same customizations.
One last bit to note. Both /etc/profile and /etc/bashrc contain settings that can be overwritten by users. As a system administrator, that poses a problem if you want to impose a global change on all users. Of these two files, the only one that lets you make such a change is /etc/profile. The reason for that is, a user can remove the "if [ -f /etc/bashrc ]" line from ~/.bashrc, and any changes to /etc/bashrc will be ignored. /etc/profile is guaranteed to be included at least once when the user initialy logs in, and that leaves it as the only viable option for including system-wide changes.
Last edited by Dark_Helmet; 01-12-2005 at 03:13 AM.
|
|
|
3 members found this post helpful.
|
09-07-2005, 09:31 PM
|
#4
|
|
LQ Newbie
Registered: Jan 2005
Location: Tokyo
Posts: 6
Original Poster
Rep:
|
Sorry for the reply really late. I was lost some tention to study linux.
I am reviewing what I was studying for LPIC rightnow and It made
a sence.
I am really appliciate for replying and your help.
|
|
|
|
09-08-2005, 01:42 AM
|
#5
|
|
Member
Registered: Jun 2005
Posts: 542
Rep:
|
Take a look at /etc/skel/.bash* and you will see that .bash_profile is set to source .bashrc which in turn sources /etc/bashrc
xterm's never use .bash_profile so most stuff should be in .bashrc
|
|
|
|
10-16-2007, 10:58 AM
|
#6
|
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Rep:
|
That was an excellent description Dark_Helmet!
Your post represents an ideal balance between "precise & technical" and "English & readable". It's got all the information a reader is likely want on the subject and you took the time to write it out so a human who's approaching it with only a little bit of prior knowledge can understand what you're talking about.
Thank You!!!
Seriously. You could write a book!

Last edited by WingnutOne; 10-16-2007 at 10:59 AM.
Reason: I hope there aren't any rules against dredging up old threads...
|
|
|
|
10-16-2007, 12:36 PM
|
#7
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
/me coughs ...
While the English was great, I don't know about the precision ;}
Firstly, according to "man bash" bash knows about a /etc/bashrc;
secondly, /etc/bash.bashrc *is* automatically used by EVERY non-
interactive shell (e.g. running a script from cron) unless
explicitly told not to.
Cheers,
Tink
|
|
|
|
10-16-2007, 05:02 PM
|
#8
|
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Rep:
|
So, Tinkster & Dark_Helmet are one and the same huh? With 17,000+ posts to your name already, you can probably get two or three volumes worth of book by the simple expedient of copy-paste-publish! 
|
|
|
|
10-16-2007, 05:43 PM
|
#9
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Errh ... nope, we're not the same person ... :}
Where did that notion come from? :D
I wouldn't be giving myself corrective feedback in this form (I don't
think ... last time I checked I wasn't schizophrenic :D)
|
|
|
|
11-13-2007, 07:47 AM
|
#10
|
|
Member
Registered: Feb 2007
Location: CT, USA
Distribution: Slackware
Posts: 61
Rep:
|
Quote:
|
Take a look at /etc/skel/.bash* and you will see that .bash_profile is set to source .bashrc which in turn sources /etc/bashrc
|
This is incorrect behavior as you're losing your ability to separate interactive from non-interactive shells.
An example of this is running separate $TERM variables for console and terminals. At the console (no X) I would prefer a $TERM variable of 'linux', but while in X my preferred terminal emulator is urxvt which requires a $TERM variable of 'rxvt-unicode'. There are many other things you might like to alias a bit differently as well. Here's another example:
alias aumix='unset DISPLAY;aumix'
As I rarely run aumix as a graphical application and almost invariably call it from a terminal emulator I have this set in ~/.bashrc (it easily could be set in /etc/bashrc if this is sourced from /.bashrc). This allows aumix to run nicely from within urxvt.
/dTd
Last edited by dTd; 11-13-2007 at 07:49 AM.
|
|
|
|
11-16-2007, 11:14 AM
|
#11
|
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Rep:
|
Quote:
Originally Posted by Tinkster
Errh ... nope, we're not the same person ... :}
Where did that notion come from? 
|
In my post #6, I said "That was an excellent description Dark_Helmet!"
I think I read more (and different) subtlety into your opening line of in post 7 "/me coughs ..." than was really there; taking it to be modest humility from the author rather than the friendly poke-in-the-ribs toward Dark_Helmet that I now understand is the way you meant it.
It doesn't look like that when I read it again today. Don't know why it struck me that way the first time. 
|
|
|
|
01-15-2011, 03:04 PM
|
#12
|
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
This is a three-year-old thread, I know. I was looking at some of my thread history when I saw Tinkster's responses. I just want to clarify a bit.
I stand by the statement that /etc/bashrc is not automatically read in. I could not find any reference to /etc/bashrc in my system's man page after multiple searches for "bashrc."
To be thorough, there IS a reference to /etc/bash.bashrc in those same man pages. Of course, /etc/bashrc and /etc/bash.bashrc are not the same file. So, modifying a file named /etc/bashrc will have no effect on /etc/bash.bashrc, and consequently, bash will not automatically read those changes. And because the OP specifically referred to /etc/bashrc (and not /etc/bash.bashrc), I answered the post from that perspective.
There would need to be some other mechanism, such as symbolic links among/between /etc/bash.bashrc and /etc/bashrc in order to allow changes to /etc/bashrc to get automatically read in by bash.
Looking carefully at Tinkster's first response in the thread shows that the difference in file name existed back when the thread was originally created; I'm not trying to receive a windfall vis-a-vis three years of bash updates. Neither am I trying to start up the discussion again unless there's further clarification (even if it's to say that I am truly, horribly wrong).
When I read through the thread as a whole, my impression was that it was left unresolved. This is a common enough question that I'm certain someone would benefit from the clarification. Maybe the thread should be locked to prevent Tinkster's schizo second personality from surfacing again...
|
|
|
|
05-17-2011, 11:25 PM
|
#13
|
|
Member
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: PCLinuxOS 2010.12, Debian Lenny
Posts: 378
Rep:
|
Excellent thread.
Just to add further clarity for anyone confused over /etc/bash.bashrc.
This file is only on Debian based Operating Systems.
You will not find it on a Red Hat based system and mostly others (Arch etc)
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:58 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|