2010-09-25 49 views
3

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

+0

环境变量也可以在这方面我想像继承。除非重置(不只是添加到),否则它可能会进一步在流程链上。但最接近我使用OS X的是一台搁置在书架上的死MacBook。 – 2010-09-25 22:15:51

+0

不完全相关,但可能有用的是,您可以使用诸如“launchctl setenv PATH”之类的命令对* all *应用程序看到的PATH进行持久更改。 – rptb1 2013-07-10 16:52:41

回答

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 

下一页bash查找~/.bash_profile~/.bash_login,和~/.profile

清单这些步骤进行,PATH构建如下:文件/etc/paths

  1. 目录添加到PATH在目录中的文件中列出
  2. 目录/etc/paths.d/附加PATH - 注,这些被附加与预先附加。
  3. ~/.bash_profile~/.bashrc文件的各种PATH={DIR_2_ADD}:"${PATH}"语句前面加上PATH
相关问题