MacOS: $PATH 里有个目录不知是如何添加进去的。Wireshark.app 的

2019-09-06 15:51:47 +08:00
 gIrl1990
fish > set -S PATH

$PATH: not set in local scope

$PATH: set in global scope, exported, with 10 elements

$PATH[1]: length=14 value=|/usr/local/bin|

$PATH[2]: length=8 value=|/usr/bin|

$PATH[3]: length=4 value=|/bin|

$PATH[4]: length=9 value=|/usr/sbin|

$PATH[5]: length=5 value=|/sbin|

$PATH[6]: length=42 value=|/Applications/Wireshark.app/Contents/MacOS|

$PATH[7]: length=75 value=|/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources|

隐藏 8 9 10

$PATH: not set in universal scope

几个已知的 Bash Startup Files 里找过了,木有~

883 次点击
所在节点    问与答
1 条回复
magicfan
2020-12-03 10:41:08 +08:00
[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
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/598614

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX