Osx
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
作為一個解決方案,這就是我所做的,我仍然對替代解決方案持開放態度,但在這裡將我的作為參考。
if [ -x /usr/libexec/path_helper ]; then paths=`/usr/libexec/path_helper -s` eval ${paths//'\$USER'/$'$USER'} fi
這只是因為第一次
path_helper
呼叫會生成帶有轉義字元串的路徑變數,如下所示:/Users/\$USER/Library
我的解決方法是在評估之前取消轉義。不過,感謝**@Gilles ‘SO-stop be evil’**幫助我發現問題。