Uncontrollable PATH

General support questions
Mike_Rochefort
Posts: 57
Joined: 2016/03/16 02:34:19

Uncontrollable PATH

Postby Mike_Rochefort » 2018/01/12 06:53:29

Maybe it's because I'm tire, but I'm at an absolute loss at the moment. For some reason my machine can't properly set the PATH variable.

For example, I've added the following to my .bashrc:

Code: Select all

# Arnold
ARNOLD=/opt/solidangle/mtoa/2018
PATH=$ARNOLD/bin:$PATH

# Redshift
REDSHIFT=/usr/redshift
PATH=$REDSHIFT/bin:$PATH

# System
export PATH=$PATH:$HOME/.local/bin:$HOME/bin


That last bit was to rule out .bash_profile from causing conflicts.

Here's the issue: when I run echo $PATH after setting the variable (and sourcing) I get:
/usr/redshift/bin:/opt/solidangle/mtoa/2018/bin:<restOfPath>:/home/user/local/bin:/home/user/bin.

On a reboot however, the path turns into:
/usr/redshift/bin:/opt/solidangle/mtoa/2018/bin:/usr/redshift/bin:/opt/solidangle/mtoa/2018/bin:<restOfPath>:/home/user/local/bin:/home/user/bin:/home/user/local/bin:/home/user/bin.

This path duplication carries on and expands through reboots, so if I were to reboot again I would then have three of each, four of each, etc etc. If I remove the PATH variable, nothing happens after sourcing it; the path remains unchanged. If I remove the offending lines completely, then I'm left with whatever the previous boots path was until I reboot the machine to get my clean PATH back.

Has anyone ever seen this before and know of a way to fix it?

Cheers,
Mike

Edit: I'm also using powerline-shell, which has be inject this into the .bashrc file:

Code: Select all

function _update_ps1() {
    PS1="$(powerline-shell $?)"
}

if [ "$TERM" != "linux" ]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMAND"
fi


I have this right after the whole /etc/bashrc sourcing, so I'm not sure if this is causing the issue. I'll try without it tomorrow.

desertcat
Posts: 299
Joined: 2014/08/07 02:17:29

Re: Uncontrollable PATH

Postby desertcat » 2018/01/12 09:30:24

Mike_Rochefort wrote:Maybe it's because I'm tire, but I'm at an absolute loss at the moment. For some reason my machine can't properly set the PATH variable.

For example, I've added the following to my .bashrc:

Code: Select all

# Arnold
ARNOLD=/opt/solidangle/mtoa/2018
PATH=$ARNOLD/bin:$PATH

# Redshift
REDSHIFT=/usr/redshift
PATH=$REDSHIFT/bin:$PATH

# System
export PATH=$PATH:$HOME/.local/bin:$HOME/bin


That last bit was to rule out .bash_profile from causing conflicts.

Here's the issue: when I run echo $PATH after setting the variable (and sourcing) I get:
/usr/redshift/bin:/opt/solidangle/mtoa/2018/bin:<restOfPath>:/home/user/local/bin:/home/user/bin.

On a reboot however, the path turns into:
/usr/redshift/bin:/opt/solidangle/mtoa/2018/bin:/usr/redshift/bin:/opt/solidangle/mtoa/2018/bin:<restOfPath>:/home/user/local/bin:/home/user/bin:/home/user/local/bin:/home/user/bin.

This path duplication carries on and expands through reboots, so if I were to reboot again I would then have three of each, four of each, etc etc. If I remove the PATH variable, nothing happens after sourcing it; the path remains unchanged. If I remove the offending lines completely, then I'm left with whatever the previous boots path was until I reboot the machine to get my clean PATH back.

Has anyone ever seen this before and know of a way to fix it?

Cheers,
Mike

Edit: I'm also using powerline-shell, which has be inject this into the .bashrc file:

Code: Select all

function _update_ps1() {
    PS1="$(powerline-shell $?)"
}

if [ "$TERM" != "linux" ]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMAND"
fi


I have this right after the whole /etc/bashrc sourcing, so I'm not sure if this is causing the issue. I'll try without it tomorrow.


Hummmmm A lot depends on exactly what you are trying to do and from where. I modified my system to show the PATH regardless of WHERE I was or WHO I was.

The Key is to modify the line in /etc/bashrc that starts: [ "$PS1" = "\\s- \\v\\\$ " ] && PS1="

Here is my entire Prompt which shows the Entire Absolute Path:
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="\[\033[1;32m\][\[\033[1;33m\]\u\[\033[1;36m\]@\h\[\033[1;31m\]\w\[\033[1;32m\]]\[\033[1;35m\]/>\[\033[1;37m\]"

And will look something like this:

[root@leopard/home/desertcat]/> or this: [desertcat@leopard~/Computers/Backup_config_files]/>

(Please forgive me I come from the time of DOS not Unix so I use > rather than $ and #. )

Mike_Rochefort
Posts: 57
Joined: 2016/03/16 02:34:19

Re: Uncontrollable PATH

Postby Mike_Rochefort » 2018/01/12 13:28:59

Thanks for the reply desertcat, but this isn’t an issue with the path to current working directory, but the actual PATH environment variable. I can’t properly set or change it. Still need to try without powerline, but I won’t be able to until later in the day.

Cheers,
Mike

pjsr2
Posts: 295
Joined: 2014/03/27 20:11:07

Re: Uncontrollable PATH

Postby pjsr2 » 2018/01/12 16:20:30

This path duplication carries on and expands through reboots, so if I were to reboot again I would then have three of each, four of each, etc etc.

Does this happen for one particular user or for any user?

If this happens across reboots, then the value must be stored somewhere on file.
If you cannot find the origin of this in your bash startup files, you could search your file system for the string "/usr/redshift/bin:/opt/solidangle/mtoa/2018/bin" and see which file is used to save this value. That may give you a clue.

Mike_Rochefort
Posts: 57
Joined: 2016/03/16 02:34:19

Re: Uncontrollable PATH

Postby Mike_Rochefort » 2018/01/12 17:02:46

Besides root, I’m the only user. I’ve su - into root and it doesn’t have those values in its environment. If I remove the values completely and reboot, then everything’s back to normal.

In regards for searching through system files, what would be the most efficient way? I’m familiar with searching for files themselves, but strings within files I haven’t done before except on a file by file manual basis with grep, ie grep string file.ext. My bash skills are not where I want them to be yet.

Cheers,
Mike

User avatar
TrevorH
Forum Moderator
Posts: 22285
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Uncontrollable PATH

Postby TrevorH » 2018/01/12 18:18:03

It just looks to me like your .bashrc is being run twice...
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

Mike_Rochefort
Posts: 57
Joined: 2016/03/16 02:34:19

Re: Uncontrollable PATH

Postby Mike_Rochefort » 2018/01/12 19:54:47

Finally back in front of my machine. I commented out everything (not much) in the ~/.bash_profile document and the problems seems to be resolved. Here's what's in there (anything with a single hash was not commented out previously, but PATH and export PATH were during the testing from my original post):

Code: Select all

# # .bash_profile

# # Get the aliases and functions
# if [ -f ~/.bashrc ]; then
#    . ~/.bashrc
# fi

# # User specific environment and startup programs

# PATH=$PATH:$HOME/.local/bin:$HOME/bin

# export PATH


I never set this file up so this is it's default state (from a clean install). My understanding was that .bash_profile was only to be sourced on login shells (like over SSH), which I guess I thought wouldn't include GUI logins or on an interactive gnome-terminal session... I've read so many articles and SO/SE posts on .bashrc .bash_profile, and .profile that I'm probably overloading at the moment and confusing myself.

Cheers,
Mike

pjsr2
Posts: 295
Joined: 2014/03/27 20:11:07

Re: Uncontrollable PATH

Postby pjsr2 » 2018/01/12 22:50:58

When bash is started as a login shell, it reads ~/.bash_profile
When bash is started as an interactive shell, it reads ~/.bashrc

Your ~/.bash_profile was identical to the default before you commented all lines out.

The problem must be arising from your additions to ~/.bashrc and I am suspicious about the powerline-shell.
Try commenting out your powerline-shell additions in ~/.bashrc only and leave ~/.bashrc as it was originally installed.
(You can find the default .bashrc and .bashrc_profile in the /etc/skel directory.)

It looks like powerline-shell is saving state in one of the following files: powerline-shell.json or ~/.powerline-shell.json
Do you have one of these files on in your user? If so, please post the contents.

Mike_Rochefort
Posts: 57
Joined: 2016/03/16 02:34:19

Re: Uncontrollable PATH

Postby Mike_Rochefort » 2018/01/12 23:07:56

I did try a 'default' setup with .bash_profile as normal and just my standard additions to .bashrc with the powerline-shell work commented out. No dice.

.powerline-shell.json

Code: Select all

{
  "segments": [
    "virtual_env",
    "username",
    "hostname",
    "ssh",
    "cwd",
    "git",
    "jobs",
    "newline",   
    "root"
  ],
  "cwd": {
    "mode": "dironly"
  },
  "theme": "mroche"
}


In all honesty I may have thought I did and then didn't try a completely 'fresh' take, but at this point I have things 'working'. As to login shells, I don't plan on doing much with any and the variables that we're in there I've transferred over into .bashrc. If for any reason I do end up in a login shell, I'll know to do . ~/.bashrc.

Cheers,
Mike

pjsr2
Posts: 295
Joined: 2014/03/27 20:11:07

Re: Uncontrollable PATH

Postby pjsr2 » 2018/01/14 15:23:47

For example, I've added the following to my .bashrc:

Code: Select all

# Arnold
ARNOLD=/opt/solidangle/mtoa/2018
PATH=$ARNOLD/bin:$PATH

# Redshift
REDSHIFT=/usr/redshift
PATH=$REDSHIFT/bin:$PATH

# System
export PATH=$PATH:$HOME/.local/bin:$HOME/bin


PATH should be set in ~/.bash_profile, not in in ~/.bashrc. ~/.bash_profile is read once when you login. ~/.bashrc is read by each shell that is started, when you start a sub-shell the addition to PATH is done a second time and again and again for deeper nested shells.

# Arnold
ARNOLD=/opt/solidangle/mtoa/2018
PATH=$ARNOLD/bin:$PATH

# Redshift
REDSHIFT=/usr/redshift
PATH=$REDSHIFT/bin:$PATH

These additions look more like system-wide configuration than user specific configuration. System-wide configuration of bash is best done by adding small scripts in the /etc/profile.d directory. /etc/bashrc loads all files with names that match *.sh in the /etc/profile.d directory.