On 05/01/2014 17:28, Tanstaafl wrote:
> Not sure what I'm missing...
> 
> I login as normal user, then su - to root...
> 
> I've created /root/.bashrc, and added the following:
> 
> export PATH="${PATH}:/path/I/want/to/add"
> 
> If I logout, then su - back into root, shouldn't I see the new path?
> 
> Manually exporting it during the session works, so obviously I'm missing
> something...
> 
> 
> 


You are running into that crazy world called "shell start-up scripts"
where nothing is as it seems and every install has different levels of
crazy.

run "man bash" and search for the section called "INVOCATION". Once you
wade through that byzantine mess, it may be apparent that ~/.bashrc is
only read when you launch an interactive non-login shell. But "su -"
starts a login shell, so .bashrc is never sourced.

Prove this by running "su" without the dash, your PATH should work then.

The usual solution is to source .bashrc from .bash_profile, this has the
effect that .bashrc is always sourced regardless of the kind of shell
you start.

Clear as mud right?

tl;dr

Long explanation:

long long ago in a land and time far far away, we have but
TheOneTrueShell(tm) and it's name was "sh". This shell was very simple
and it's start up scripts followed a grand Unix tradition:

/etc/profile contained the global settings for all users
~/.profile contained a user's specific settings

And so the world was good. Until bash.

The authors of bash figured they should provide extra and wonderful ways
of providing bash-specific startup scripts. You'd think they'd do it so
the user could put their personal stuff for all shells into ~/.profile
and bash stuff into ~/.bash_profile.

But no, nothing so simple. Bash first looks for ~/.bash_profile and if
it finds it, it ignores ~/.profile entirely. So people would just add
". ~/.profile" to .bash_profile and be done with it.

Then there's a distinction between a login shell (what you get at login,
or with su -) and a non-login shell (what you get with su or usually
with konsole, gnome-terminal etc). Why this difference exists, I do not
know. Maybe it's to save 512 precious bytes of environment memory.

A non-login shell reads only ~/.bashrc, presumably because the shell was
launched for something else (an Xsession, or a running shell) that had a
full environment set up already and there was no need to repeat it.

Head spinning yet? Just be done with all that nonsense and do this:

Put this line as the only non-comment line in .bash_profile

[[ -f ~/.bashrc ]] && . ~/.bashrc

and put all your shell start-up stuff in .bashrc (moving them out of
.bash_profile if necessary


This way everything is still unbelievably complex but at least the
visible problems mostly just go away


-- 
Alan McKinnon
[email protected]


Reply via email to