path_helper 未从 etc 目录加载路径

path_helper 未从 etc 目录加载路径

目前我使用的是 macOS Catalina,但几个版本都是一样的。

/etc/zprofile或者/etc/profile在旧版本上使用 bash 时)我默认有这样的内容:

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

此外,我还创建了一个文件/etc/paths.d/android。内容是

/Users/$USER/Library/Android/sdk/platform-tools
/Users/$USER/Library/Android/sdk/tools
/Users/$USER/Library/Android/sdk/tools/bin

但是,当我启动终端时,终端无法在这些文件夹中找到我的二进制文件:

zsh: command not found: adb

不知道为什么,但解决方法是复制路径辅助行,如下所示?

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
    eval `/usr/libexec/path_helper -s`
fi

所以,这是我的问题,为什么会发生这种情况以及这种解决方法实际上是如何运作的?

我厌倦了解决方法,因为它只是在每次更新时被删除。


** 编辑 **

没有重复:

PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Users/\$USER/Library/Android/sdk/platform-tools:/Users/\$USER/Library/Android/sdk/tools:/Users/\$USER/Library/Android/sdk/tools/bin:/Users/\$USER/Library/Flutter/bin:/Applications/Wireshark.app/Contents/MacOS:/Users/$USER/Library/Android/sdk/platform-tools:/Users/$USER/Library/Android/sdk/tools:/Users/$USER/Library/Android/sdk/tools/bin:/Users/$USER/Library/Flutter/bin"; export PATH;
print -lr -- $path[@]
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Applications/VMware Fusion.app/Contents/Public
/Users/$USER/Library/Android/sdk/platform-tools
/Users/$USER/Library/Android/sdk/tools
/Users/$USER/Library/Android/sdk/tools/bin
/Users/$USER/Library/Flutter/bin
/Applications/Wireshark.app/Contents/MacOS

有重复:

PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Users/\$USER/Library/Android/sdk/platform-tools:/Users/\$USER/Library/Android/sdk/tools:/Users/\$USER/Library/Android/sdk/tools/bin:/Users/\$USER/Library/Flutter/bin:/Applications/Wireshark.app/Contents/MacOS:/Users/$USER/Library/Android/sdk/platform-tools:/Users/$USER/Library/Android/sdk/tools:/Users/$USER/Library/Android/sdk/tools/bin:/Users/$USER/Library/Flutter/bin:/Users/guness/Library/Android/sdk/platform-tools:/Users/guness/Library/Android/sdk/tools:/Users/guness/Library/Android/sdk/tools/bin:/Users/guness/Library/Flutter/bin"; export PATH;
print -lr -- $path[@]
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Applications/VMware Fusion.app/Contents/Public
/Users/$USER/Library/Android/sdk/platform-tools
/Users/$USER/Library/Android/sdk/tools
/Users/$USER/Library/Android/sdk/tools/bin
/Users/$USER/Library/Flutter/bin
/Applications/Wireshark.app/Contents/MacOS
/Users/guness/Library/Android/sdk/platform-tools
/Users/guness/Library/Android/sdk/tools
/Users/guness/Library/Android/sdk/tools/bin
/Users/guness/Library/Flutter/bin

答案1

作为一个解决方案,这就是我所做的,我仍然对替代解决方案持开放态度,但将我的解决方案放在这里作为参考。

if [ -x /usr/libexec/path_helper ]; then
    paths=`/usr/libexec/path_helper -s`
    eval ${paths//'\$USER'/$'$USER'}
fi

这只是因为第一次path_helper调用生成带有转义字符串的路径变量,如下所示:/Users/\$USER/Library而我的解决方法是在评估之前取消转义。


尽管如此,还是要感谢@Gilles“所以-别再邪恶了”帮助我找出问题。

相关内容