Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 在OS X上的Terminal.app中打开BASH shell时,如何设置PATH env变量?_Macos_Bash_Shell_Path_Terminal - Fatal编程技术网

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

Macos 在OS X上的Terminal.app中打开BASH shell时,如何设置PATH env变量?,macos,bash,shell,path,terminal,Macos,Bash,Shell,Path,Terminal,在OS X上的Terminal.app中打开BASH shell时,哪些启动脚本按调用顺序设置路径变量?我找到了罪魁祸首。秘密酱汁是/usr/libexec/path\u helper它在文件/etc/paths和目录/etc/paths.d/中查找 第一个bashsources/etc/profile,它执行以下代码: if [ -x /usr/libexec/path_helper ]; then eval `/usr/libexec/path_helper -s` # Th

在OS X上的Terminal.app中打开BASH shell时,哪些启动脚本按调用顺序设置
路径变量?

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

第一个
bash
sources
/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\u配置文件
~/.bash\u登录名
,以及
~/.profile

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

  • 文件
    /etc/PATH
    中的目录将添加到
    PATH
  • 目录
    /etc/paths.d/
    中的文件中列出的目录被附加到
    路径
    -注意,这些目录是附加的,而不是附加在前面的
  • 各种
    PATH={DIR\u 2\u ADD}:“${PATH}”
    语句在我的
    ~/.bash\u配置文件
    ~/.bashrc
    文件前加
    PATH

  • 我想,在这种情况下,环境变量也可能被继承。除非重置(而不仅仅是添加到),否则它可能会在流程链的更上层。但我最接近使用OS X的是一台放在书架上的死气沉沉的MacBook。这并不完全相关,但可能有用的是,您可以使用类似于
    launchctl setenv PATH的命令对所有应用程序看到的路径进行持久更改。