How is the env PATH variable set when opening the BASH shell in Terminal.app in OS X?

What startup scripts - in the order in which they are called - set a variable PATHwhen opening the BASH shell in Terminal.app in OS X?

+3
source share
1 answer

I found a criminal. There was a secret sauce /usr/libexec/path_helper; it looks in a file /etc/pathsand in a directory /etc/paths.d/.

The first bashsource /etc/profilethat 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

Further bashsearches ~/.bash_profile, ~/.bash_loginand ~/.profile.

Listing these steps is PATHcreated as follows:

  • /etc/paths PATH
  • , /etc/paths.d/, PATH - , , .
  • PATH={DIR_2_ADD}:"${PATH}" ~/.bash_profile ~/.bashrc preend PATH
+7

Source: https://habr.com/ru/post/1766584/


All Articles