Bash Environment Variables – Where is My Bash PATH Set?

bashenvironment-variablespath

I want to remove ~/bin from my PATH.  I set it up months ago when Linux (Ubuntu) was very new to me, but I don't know how I added it…

Nothing shows up when I search all the files listed below.
Where else could it be being set?  It is being pre-pended after $HOME/.profile prefixes PATH with $HOME/bin

If it makes any difference, I get the same PATH from both the command-prompt and a running script.

#!/bin/bash
{
  echo "first dir of PATH is: '${PATH%%:*}'"
  shopt -s nullglob
  cat \
    /etc/profile \
    /etc/bash.bashrc \
    /etc/profile.d/*.sh \
    $HOME/.bashrc \
    $HOME/.bash_aliases \
    /etc/bash_completion \
    $HOME/.bash_completion* \
    $HOME/.profile \
    $HOME/.profile_zap \
    $HOME/.bash_profile* \
    $HOME/.bash_login* \
  | sed -rne '/~\/bin/p'
}

Output is:

first dir of PATH is: '~/bin'

Best Answer

You might want to trace the full environment load on login. Just an idea.

Since /etc/profile is the first file sourced, you can add to it at the very top a:

set -x
exec 2> /tmp/debug.log

Then open a new terminal and do a bash -l; after that go to the original terminal and remove the lines added (you want to have a working environment, don't you?).

You should end with a full trace of all the steps of the loading_the_bash_environment at /tmp/debug.log. It will be a loooong file.

With that you must be able to locate where the "~/bin" gets into your PATH

I'd look first for a grep of all the files sourced. From your post I bet that the ~/bin in the path is set in a different file of those you've listed.

Related Question