Matthew Weier O'Phinney wrote: > 1) In $HOME/.bashrc (this could be in the profile somewhere; I don't > manage a large system), I set and export any environment variables I > need in my login shell. > > 2) In $HOME/.bash_profile, I have the following lines at the top of the > file: > # Get the aliases and functions > if [ -f ~/.bashrc ]; then > . ~/.bashrc > fi > > 3) In $HOME/.xsession (which is called by xdm, gdm, and kdm), I add the > very same lines above at the top of that file, before any specific items > needed for the xsession. > > Doing the above means I only need to change one file when I want to > change my environment, and ensures that that environment is available > whenever and whereever I'm working (login shell, non-login shell, and X > session).
I don't think .bashrc is the right place to be setting environment variables, because it means that you will fail to inherit variables from a parent shell, since .bashrc is read by all interactive bashes. Thus if .bashrc contains: export FOO=bar You log in, and do the following: % echo $FOO bar % export FOO=quux % echo $FOO quux % bash % echo $FOO bar % exit % echo $FOO quux Note how your manual change from FOO=bar to FOO=quux was lost in the subshell, because the subshell read .bashrc again. My solution to this problem is to put all exported variables into another file, .bash_vars, which is sourced from .bash_profile and .xsession. This way, the variables all get set properly, but only once. Craig
pgp00000.pgp
Description: PGP signature