LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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

Reply
 
Search this Thread
Old 01-05-2005, 12:31 AM   #1
Takayuki
LQ Newbie
 
Registered: Jan 2005
Location: Tokyo
Posts: 6

Rep: Reputation: 0
Post /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.
Old 01-11-2005, 11:26 PM   #2
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 61
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
 
Old 01-12-2005, 04:12 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
/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 04:13 AM.
 
3 members found this post helpful.
Old 09-07-2005, 10:31 PM   #4
Takayuki
LQ Newbie
 
Registered: Jan 2005
Location: Tokyo
Posts: 6

Original Poster
Rep: Reputation: 0
Wink

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.
 
Old 09-08-2005, 02:42 AM   #5
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
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
 
Old 10-16-2007, 11:58 AM   #6
WingnutOne
Member
 
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Rep: Reputation: 16
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 11:59 AM. Reason: I hope there aren't any rules against dredging up old threads...
 
Old 10-16-2007, 01:36 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
/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
 
Old 10-16-2007, 06:02 PM   #8
WingnutOne
Member
 
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Rep: Reputation: 16
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!
 
Old 10-16-2007, 06:43 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
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)
 
Old 11-13-2007, 08:47 AM   #10
dTd
Member
 
Registered: Feb 2007
Location: CT, USA
Distribution: Slackware
Posts: 62

Rep: Reputation: 8
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 08:49 AM.
 
Old 11-16-2007, 12:14 PM   #11
WingnutOne
Member
 
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Rep: Reputation: 16
Quote:
Originally Posted by Tinkster View Post
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.
 
Old 01-15-2011, 04:04 PM   #12
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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...
 
Old 05-18-2011, 12:25 AM   #13
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: PCLinuxOS 2010.12, Debian Lenny
Posts: 387

Rep: Reputation: 38
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)
 
  


Reply

Tags
bashrc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/etc/profile vs /etc/bashrc maybbach Linux - Newbie 6 04-22-2005 10:50 AM
/etc/profile vs. /etc/bash.bashrc jbrashear Debian 3 03-11-2004 04:49 PM
RH9 bashrc and profile magnusprime Red Hat 5 09-01-2003 06:32 PM
Where's my .bashrc or .profile t1mc00per Linux - Software 6 03-03-2003 11:35 AM
.bashrc,profile.local Cichlid Linux - Distributions 1 01-08-2002 06:22 AM


All times are GMT -5. The time now is 07:49 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration