在OS X上的Terminal.app中打开BASH shell时,如何设置PATH env变量?

Mat*_*kin 3 macos bash shell terminal path

什么启动脚本 - 按照它们被调用的顺序 - PATH在OS X上的Terminal.app中打开BASH shell时设置变量?

Mat*_*kin 7

我找到了罪魁祸首.秘密酱是/usr/libexec/path_helper它在文件/etc/paths和目录中查找/etc/paths.d/.

第一个执行以下代码的bash/etc/profile:

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
Run Code Online (Sandbox Code Playgroud)

接下来bash验看~/.bash_profile,~/.bash_login~/.profile.

列出这些步骤,PATH构建如下:

  1. 文件中的目录/etc/paths被添加到PATH
  2. 在目录中的文件中列出的目录/etc/paths.d/追加PATH-请注意,这些附加与被预先考虑.
  3. PATH={DIR_2_ADD}:"${PATH}"~/.bash_profile~/.bashrc文件中的各种语句都是前置的PATH