35 Comments
- mancat, on 10/12/2007, -0/+24Honestly, that's not any more intuitive.
- GMorgan, on 10/12/2007, -0/+21One only gets called at login (.bash_profile), the other gets called every time you open a shell (.bashrc). This means that setting bash variables in .bashrc can have strange effects. If you set the PATH variable such that it is self referencing and adds a few more paths the the end of the current path in .bashrc, everytime you pull down a terminal the PATH variable will grow. If you have a machine that has a long uptime this could slow the machine down since each time you try to tab complete something it will search some of the paths once for each time you've opened a terminal in that session which could be thousands of times.
In any case, set the PATH variable or any other self referential variable in .bash_profile.
//edit - the calling one from the other thing is madness as well. A certain way for strange things to happen.// - iDiggIt42, on 10/12/2007, -1/+17I guess vinodkone can't bother to capitalize, spell out the word "you", or come up with a more descriptive/appropriate adjective than "cute"?
- RoadWarriorX11, on 10/12/2007, -0/+10One of the great mysteries of life SOLVED
I for one am proud of learning something new everyday -_- - diggathon, on 10/12/2007, -0/+10Dugg for not being ubuntu specific
- jktstance, on 10/12/2007, -2/+11Buried for the use of "u" and no capitalization.
- Mootabolife, on 10/12/2007, -0/+8many don't.. like most IT guys out of college.
- phjr, on 10/12/2007, -2/+7Probably many people know it, but I suppose many don't.
- DevilDogs, on 10/12/2007, -0/+4It's OK to call .bashrc from .bash_profile as long as you're careful what commands you put in .bashrc. However you should never call .bash_profile from .bashrc. If you really want to execute .bash_profile, just start bash with a '-l' (or a '--login' if you prefer) option.
- astrosmash, on 10/12/2007, -0/+4You are missing something.
By default, Terminal.app opens a login shell for each window, hence reading .bash_profile. This is configurable through Terminal's perferences.
Xterm, by default, does not open a login shell for each window, hence reading .bashrc. "xterm -ls" opens Xterm with a login shell. - mancat, on 10/12/2007, -0/+3Most introductory Unix classes do teach the basics of at least bash and csh, including this.
- sishgupta, on 10/12/2007, -0/+3Why the hell is this cute?!
- Otto, on 10/12/2007, -0/+3Calling one from the other is generally a bad idea. Ideally, you'd take the common pieces and put them in a third script, which both of them call.
- TheEgghead, on 10/12/2007, -3/+6Damn right. ZSH gets this right by having clear, appropriately named files:
.zshenv is executed for all shells THEN
.zprofile is executed for login shells THEN
.zshrc is executed for interactive shells THEN
.zlogin is executed for login shells (for csh compatibility)
There's even .zlogout for when you logout.
This way you don't have to do any silliness about calling one file for the other. The world would truly be a better place if everyone used zsh.
-Matt - inactive, on 10/12/2007, -0/+3Men, I'm sure you didn't understand a ***** about the article...
- mpost89, on 10/12/2007, -0/+2This is worthless. It doesn't explain the differences at all. It only tells you to call one of the scripts from the other, which is what everybody already does, but without understanding why it might create problems.
The title is very misleading. Bury this. - scrag10, on 10/12/2007, -0/+2Yes... I feel stupid
- jimmiejaz, on 10/12/2007, -0/+2Am I mistaken here, or does this imply that BASH is the only shell for Linux by it's wording? We all know, it's default on most distros.
Let's remember /etc/profile and it's friends that are read first, globally. - SjRaptor, on 10/12/2007, -0/+2there's even .bash_logout for when you logout of bash. it all comes down to user preference. I like bash and also tcsh.
- 5plic3r, on 10/12/2007, -0/+1True, but some of the comments below the article do.
- klepto, on 10/12/2007, -2/+3.zshrc ftw
- burke, on 10/12/2007, -1/+2That's exactly the same setup, only there are about 5 different files for different events and combinations thereof.
....but maybe there is something to this whole zsh thing. I hear a lot about it. Is it worth making the switch from bash? - chair, on 10/12/2007, -1/+2That explanation was way cuter than the one article ;-)
- timmerk15, on 10/12/2007, -0/+1So where does .profile come into play? I have both .profile and .bash_profile in OS X.
- Plugh, on 10/12/2007, -0/+1Move over, Dennis and Ken -- a new Unix wizard walks among us!
- 5plic3r, on 10/12/2007, -0/+1Here's one of the page's comments I found informative:
"You should use ~/.profile for setting environment variables or executing login scripts. That way if you decide to switch to another shell (or if bash is for some reason unavailable - due to a disk failure for example) you won't need to move those scripts out of ~/.bash_profile - they'll be appropriately executed from ~/.profile.
Any bash-specific settings should be set in ~/.bashrc, so that they will be set even if you execute bash from another shell or xterm (ie if bash is not your login shell for that session).
All of this is clearly stated in the bash man page (ie 'man bash' at the command line), as well as the user guide." - aule, on 10/12/2007, -0/+1@astrosmash
Thanks, that clears up things.
-aule - umbrae, on 10/12/2007, -0/+0Article text, it's getting killed:
One of the things I always have trouble remembering when working with linux is what is the correct ".profile" to edit when I want to automatically set environmental variables and such for my shell.
Included in Debian Woody are both .bash_profile, and .bashrc. I can never remember the difference between these two.
According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
What I take this to mean is that when I login when using a console, either physically at the machine or using ssh, .bash_profile is executed.
However, if I launch a terminal within a windowing system such as KDE, launch the Emacs *shell* mode, or execute /bin/bash from within another terminal then .bashrc is executed.
At any rate, the point is generally moot because most people edit the files so one calls the other anyway.
To do this under Debian Woody, we open .bash_profile and uncomment the following lines (under the comment # include .bashrc if it exists):
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
Now when we login to our machine from a console, .bashrc will get called. As a bonus, in Debian Woody, the defualt .bashrc turns on coloring when running the ls command. Nice! - hackerssidekick, on 10/12/2007, -1/+1I don't bother with calling one from the other. I instead edit one and symlink the other to it. Problem solved!
- aule, on 10/12/2007, -2/+1Of course this doesn't easily translate over to Mac OS X (please leave the flames for another thread). Instead of calling .bash_profile by default OS X calls /etc/profile during login, setting the enivronment variables, which you can add to in either .profile or .bash_profile. The problem lies with using X11 under OS X, for whatever reason the environment variables are not read from .profile nor .bash_profile. You have to set these variables using .bashrc, leading to a pain in the ol' ass. Or am I missing something...
- tehmoth, on 10/12/2007, -1/+0ugh, bloated-again-shell, no thanks. pdksh and csh work just fine.
- Boghiu, on 10/12/2007, -3/+1Very interesting ;)
- fleabag, on 10/12/2007, -4/+1Where are the ubuntu cheerleaders?!?!
- scrag10, on 10/12/2007, -6/+1All of your .zshrc are belong to us


What is Digg?
Browsing Digg on your phone just got easier with our enhancements to the