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,bash
should be called insh
-way and it's not a login shell. - To further make sure the
/etc/profile
,$HOME/.bash_profile
,$HOME/.bashrc
doesn'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
PATH
is inherited from parent process, which in this case is thegnome-terminal-server
. - the
PATH
is modifed in some script that is sourced mysteriously bysh
at some point. - the
PATH
is 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/environ
where$PPID
is the PID ofgnome-terminal-server
shows that itsPATH
variable is/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
, which does not contain what we are looking for.In the
sh
we have just opened, runexport -n PATH
andsh -x
, I can see nothing get sourced during the init process of this newsh
. And itsPATH
is 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 -x
as the custom command? Which distro is this? What doesgnome-terminal-server
'sPATH
containd?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. I'm on Fedora 23. According to procfs, the parentgnome-terminal-server
is PATH isPATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
. I'll update the question to include these information.sh -x
custom command environment,echo $TERM
outputsxterm-256color
.