views:

40

answers:

1

What startup scripts—in the order that they are called—set the PATH variable when opening a BASH shell in Terminal.app on OS X?

+1  A: 

I've found the culprit. The secret sauce was /usr/libexec/path_helper it looks in the file /etc/paths and in the directory /etc/paths.d/.

First bash sources /etc/profile which executes the following code:

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
    # The above line is the secret sauce, so to say...
    # First is adds default PATH values from the file /etc/paths
    # Then all files in the /etc/paths.d/ directory are read and directories listed
    # in each file (one per line) are appended to PATH
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

Next bash looks for ~/.bash_profile, ~/.bash_login, and ~/.profile.

Listing these steps out, PATH is built as follows:

  1. Directories in the file /etc/paths are added to PATH
  2. Directories listed in the files in the directory /etc/paths.d/ are appended to PATH — Note, that these are appended versus being prepended.
  3. Various PATH={DIR_2_ADD}:"${PATH}" statements in my ~/.bash_profile and ~/.bashrc files are prepend PATH
Matthew Rankin