LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   why does my $PATH keeps changing (https://www.linuxquestions.org/questions/linux-newbie-8/why-does-my-%24path-keeps-changing-4175552361/)

jzoudavy 09-01-2015 05:06 PM

why does my $PATH keeps changing
 
Hi all

I got redhat 6.5, and every once in a while my $PATH variable for root user changes. I am getting really really pissed off about this. It is always the same: /usr/sbin disappears and I have to add it back.

I think it is one of the tcl shell environments that the other users on this machine like to use so much causing it but I can't be sure.

anyway I can check?

suicidaleggroll 09-01-2015 05:10 PM

What do you mean you have to "add it back"? Where does it disappear from?

jzoudavy 09-01-2015 05:16 PM

my root user's $PATH.

Code:

# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/sbin


the /usr/sbin is what keeps disappearing.

suicidaleggroll 09-01-2015 05:22 PM

I understand that, I mean the PATH gets set by root's login scripts, .bashrc, .profile, etc. just like regular users, so which login script is /usr/sbin disappearing from and where are you adding it back?

On my CentOS system, /usr/sbin gets added to root's PATH in /etc/profile:
Code:

if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else ...

Is it possible you're sometimes accidentally running "su" instead of "su -"? The latter will update root's environment variables, the former won't.

astrogeek 09-01-2015 05:29 PM

As suicidaleggroll points out, the environment depends on how you get root...

1. Login as root - you get root's full environment
2. su - to root from user login, you get root's full environment
3. su to root from user login, you retain user's environment

jzoudavy 09-02-2015 10:01 AM

Hey all,

So right now I can't reproduce this but next time it happens I will take another look.


So here is my user's path:
as you can see it has all the directories that I need in it.

Code:

$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/bin

Then I su into root

Code:

$ su root
 
$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/bin

and I still retain my user's $PATH, which is fine.

and if I do this:

Code:

# su root -
# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/bin

I am now using root's $PATH. Which is also fine.

but at some point even when I do
Code:

su root -
I still find /usr/sbin is no longer in the root's $PATH.

suicidaleggroll 09-02-2015 10:09 AM

Code:

su root -
is NOT the same as
Code:

su -
As you can see from your output, the PATH did not change, you were still using your regular user's PATH.

What you're looking for is
Code:

su - root
Although the "root" is redundant since that's the default when no user is given.

jzoudavy 09-02-2015 10:34 AM

AAAAAHHH

ok, now it makes sense. thank you. It works as advertised now.


All times are GMT -5. The time now is 04:46 AM.