I guess gnome-terminal might have modified PATH environ variable when invoking shell.
Specifically, $HOME/.local/bin:$HOME/bin will always be appended to PATH.
I did the following experiment to demonstrate this:
- Open a gnome-terminal
- traverse through "Edit" -> "Preference" -> "Profiles" and "Edit" your current profile (which is "Unamed" for me)
- Under the "Command" tab, check "Run a custom command instead of my shell" and
fill in the following input area with
sh. In this way,bashshould be called insh-way and it's not a login shell. - To further make sure the
/etc/profile,$HOME/.bash_profile,$HOME/.bashrcdoesn't get sourced, we rename these files temporarily. (Actually, these files should NOT get sourced already, as we are invoking a non-loginsh.) Now, open a new gnome-terminal window and run
echo $PATH. Here is what I got:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/naitree/.local/bin:/home/naitree/bin
I don't understand why the last two path appeared in PATH.
Based on this fact, I think the following possible explanations exists:
- the
PATHis inherited from parent process, which in this case is thegnome-terminal-server. - the
PATHis modifed in some script that is sourced mysteriously byshat some point. - the
PATHis modifed when gnome-terminal-server forks off the subprocess.
Now I think I have ruled out the #1 and the #2 possibilties:
cat /proc/$PPID/environwhere$PPIDis the PID ofgnome-terminal-servershows that itsPATHvariable is/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin, which does not contain what we are looking for.In the
shwe have just opened, runexport -n PATHandsh -x, I can see nothing get sourced during the init process of this newsh. And itsPATHis clean:/usr/local/bin:/usr/bin
Which leaves me the last possibility.
Did I missed something? Is gnome-terminal the culprit for the mysteriously modified PATH?
Update:
I just tried sh -x as the custom command. Upon opening gonme-terminal, I didn't see anything get sourced. But, echo $PATH says that $HOME/.local/bin and $HOME/bin are there.
Here are distro related info:
- Fedora 23 (4.4.8-300.fc23.x86_64)
- bash version 4.3.42(1)-release (x86_64-redhat-linux-gnu)
Update2:
I just tried:
- Add
echo "$PATH"at the very beginning of~/.bashrc. - opening gnome-terminal with bash in the default non-login shell mode, with custom command
bash -x.
Based on debug ouput, I observed that the ~/.bashrc is the starting point of script sourcing. But the $HOME/.local/bin and $HOME/bin are already there in PATH even before that.
sh -xas the custom command? Which distro is this? What doesgnome-terminal-server'sPATHcontaind?sh -xas the custom command. Upon opening gonme-terminal, I didn't see anything get sourced. But,echo $PATHsays that$HOME/.local/binand$HOME/binare there. I'm on Fedora 23. According to procfs, the parentgnome-terminal-serveris PATH isPATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin. I'll update the question to include these information.sh -xcustom command environment,echo $TERMoutputsxterm-256color.