magicfan 最近的时间轴更新
magicfan

magicfan

V2EX 第 64010 号会员,加入于 2014-06-01 12:13:16 +08:00
magicfan 最近回复了
2020-12-03 10:41:08 +08:00
回复了 gIrl1990 创建的主题 问与答 MacOS: $PATH 里有个目录不知是如何添加进去的。Wireshark.app 的
[How to use /etc/paths.d to add executable files to my path?]( https://apple.stackexchange.com/questions/128897/how-to-use-etc-paths-d-to-add-executable-files-to-my-path)
[Use /etc/paths or /etc/paths.d to add items to the PATH in macOS Sierra?]( https://unix.stackexchange.com/questions/342574/use-etc-paths-or-etc-paths-d-to-add-items-to-the-path-in-macos-sierra)

The paths in `/etc/paths.d/` are added to the path by `/usr/libexec/path_helper`, which is run from `/etc/profile`, `/etc/zprofile`, and `/etc/csh.login`.

可执行 `man path_helper` 查看相关说明。

以下为 macOS ZSH 下的 PATH 变量:

```
$ echo $PATH | awk 'BEGIN{RS=":"} {print}'
# 省略在 ~/.zshrc 中追加在 PATH 前面的配置
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/opt/X11/bin
/Library/Apple/usr/bin
/Applications/Wireshark.app/Contents/MacOS
# 省略在 ~/.zshrc 中追加在 PATH 后面的配置
```

前面 5 个为 `/etc/paths` 中预定义的路径;后面 3 个为 `/etc/paths.d` 中配置的环境变量:

```
$ ls -1 /etc/paths.d/
100-rvictl
40-XQuartz
Wireshark
```

每个文件里面包含一行可执行路径,被 `/etc/profile` 或 `/etc/zprofile` 执行 path_helper 加载到 PATH 环境变量中:

```
$ cat /etc/paths.d/40-XQuartz
/opt/X11/bin
$ cat /etc/paths.d/100-rvictl
/Library/Apple/usr/bin
$ cat /etc/paths.d/Wireshark
/Applications/Wireshark.app/Contents/MacOS
```
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3024 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 08:16 · PVG 16:16 · LAX 01:16 · JFK 04:16
Developed with CodeLauncher
♥ Do have faith in what you're doing.