public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Updating $PATH variable permanently for root not working
@ 2014-01-05 15:28 Tanstaafl
  2014-01-05 20:43 ` Alecks Gates
  2014-01-05 21:14 ` Alan McKinnon
  0 siblings, 2 replies; 7+ messages in thread
From: Tanstaafl @ 2014-01-05 15:28 UTC (permalink / raw
  To: gentoo-user

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...


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-user] Updating $PATH variable permanently for root not working
  2014-01-05 15:28 [gentoo-user] Updating $PATH variable permanently for root not working Tanstaafl
@ 2014-01-05 20:43 ` Alecks Gates
  2014-01-05 21:14 ` Alan McKinnon
  1 sibling, 0 replies; 7+ messages in thread
From: Alecks Gates @ 2014-01-05 20:43 UTC (permalink / raw
  To: gentoo-user

On Sun, Jan 5, 2014 at 9:28 AM, Tanstaafl <tanstaafl@libertytrek.org> 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...
>

Personally, I had to create /root/.bash_profile for .bashrc:

~ # cat .bash_profile
# /etc/skel/.bash_profile

# This file is sourced by bash for login shells.  The following line
# runs your .bashrc and is recommended by the bash info pages.
[[ -f ~/.bashrc ]] && . ~/.bashrc

-- 
Alecks Gates


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-user] Updating $PATH variable permanently for root not working
  2014-01-05 15:28 [gentoo-user] Updating $PATH variable permanently for root not working Tanstaafl
  2014-01-05 20:43 ` Alecks Gates
@ 2014-01-05 21:14 ` Alan McKinnon
  2014-01-05 22:05   ` Michael Orlitzky
  2014-01-06 12:28   ` Tanstaafl
  1 sibling, 2 replies; 7+ messages in thread
From: Alan McKinnon @ 2014-01-05 21:14 UTC (permalink / raw
  To: gentoo-user

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
alan.mckinnon@gmail.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-user] Updating $PATH variable permanently for root not working
  2014-01-05 21:14 ` Alan McKinnon
@ 2014-01-05 22:05   ` Michael Orlitzky
  2014-01-06 21:04     ` Alan McKinnon
  2014-01-06 12:28   ` Tanstaafl
  1 sibling, 1 reply; 7+ messages in thread
From: Michael Orlitzky @ 2014-01-05 22:05 UTC (permalink / raw
  To: gentoo-user

On 01/05/2014 04:14 PM, Alan McKinnon wrote:
> 
> 
> This way everything is still unbelievably complex but at least the
> visible problems mostly just go away
> 

There is an apparently empty directory, /etc/skel, that upon closer
inspection contains some nice default bash junk:

  $ ls -a /etc/skel/
  total 32K
  drwxr-xr-x   3 root root 4.0K 2013-06-06 10:53 .
  drwxr-xr-x 113 root root  12K 2014-01-05 01:24 ..
  -rw-r--r--   1 root root  127 2013-06-06 10:53 .bash_logout
  -rw-r--r--   1 root root  193 2013-06-06 10:53 .bash_profile
  -rw-r--r--   1 root root  551 2013-06-06 10:53 .bashrc
  drwx------   2 root root 4.0K 2007-11-23 14:25 .ssh

The 'useradd' program {might,should} install these for you; if not it
can be coaxed into it with the --skel flag.

The .bash_profile in there does what Alan suggests.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-user] Updating $PATH variable permanently for root not working
  2014-01-05 21:14 ` Alan McKinnon
  2014-01-05 22:05   ` Michael Orlitzky
@ 2014-01-06 12:28   ` Tanstaafl
  2014-01-06 21:05     ` Alan McKinnon
  1 sibling, 1 reply; 7+ messages in thread
From: Tanstaafl @ 2014-01-06 12:28 UTC (permalink / raw
  To: gentoo-user

On 2014-01-05 4:14 PM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
> 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

Wow... or rather... UGH

Anyway, thanks Alan, that did indeed do the trick...

:)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-user] Updating $PATH variable permanently for root not working
  2014-01-05 22:05   ` Michael Orlitzky
@ 2014-01-06 21:04     ` Alan McKinnon
  0 siblings, 0 replies; 7+ messages in thread
From: Alan McKinnon @ 2014-01-06 21:04 UTC (permalink / raw
  To: gentoo-user

On 06/01/2014 00:05, Michael Orlitzky wrote:
> On 01/05/2014 04:14 PM, Alan McKinnon wrote:
>>
>>
>> This way everything is still unbelievably complex but at least the
>> visible problems mostly just go away
>>
> 
> There is an apparently empty directory, /etc/skel, that upon closer
> inspection contains some nice default bash junk:
> 
>   $ ls -a /etc/skel/
>   total 32K
>   drwxr-xr-x   3 root root 4.0K 2013-06-06 10:53 .
>   drwxr-xr-x 113 root root  12K 2014-01-05 01:24 ..
>   -rw-r--r--   1 root root  127 2013-06-06 10:53 .bash_logout
>   -rw-r--r--   1 root root  193 2013-06-06 10:53 .bash_profile
>   -rw-r--r--   1 root root  551 2013-06-06 10:53 .bashrc
>   drwx------   2 root root 4.0K 2007-11-23 14:25 .ssh
> 
> The 'useradd' program {might,should} install these for you; if not it
> can be coaxed into it with the --skel flag.
> 
> The .bash_profile in there does what Alan suggests.

Ah, but there's a snag with the root account which is what Charles is using

"useradd root" is never run on a Unix boot and /etc/skel is only copied
over by using useradd. The root account is created at install time
unpacking the stage 3 IIRC so the profiles it gets are whatever is in
the tarball.

To get /etc/skel for root, one has to copy the file.
I keep forgetting to do this myself on installs, this the main reason
why I know more about bash startup than I should :-)

-- 
Alan McKinnon
alan.mckinnon@gmail.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [gentoo-user] Updating $PATH variable permanently for root not working
  2014-01-06 12:28   ` Tanstaafl
@ 2014-01-06 21:05     ` Alan McKinnon
  0 siblings, 0 replies; 7+ messages in thread
From: Alan McKinnon @ 2014-01-06 21:05 UTC (permalink / raw
  To: gentoo-user

On 06/01/2014 14:28, Tanstaafl wrote:
> On 2014-01-05 4:14 PM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
>> 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
> 
> Wow... or rather... UGH
> 
> Anyway, thanks Alan, that did indeed do the trick...
> 
> :)
> 
> 
> 


You're welcome. I figured you deserved to have the whole ugly truth for
your reading pleasure, with the option of a tl;dr of course ;-)

-- 
Alan McKinnon
alan.mckinnon@gmail.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-06 21:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-05 15:28 [gentoo-user] Updating $PATH variable permanently for root not working Tanstaafl
2014-01-05 20:43 ` Alecks Gates
2014-01-05 21:14 ` Alan McKinnon
2014-01-05 22:05   ` Michael Orlitzky
2014-01-06 21:04     ` Alan McKinnon
2014-01-06 12:28   ` Tanstaafl
2014-01-06 21:05     ` Alan McKinnon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox