Linux - GeneralThis 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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Distribution: Ubuntu, Debian, Various using VMWare
From "man bash"
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.
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)
/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:
if [ -f /etc/bashrc ] ; then
/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:
alias testecho='echo this is a test!'
cat > ~/test_script.bash << EOF
chmod u+x ~/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.
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.
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...
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.
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.
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.
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...