網上說法都是
發現zsh加載的是 ~/.zshrc文件,而 ‘.zshrc’ 文件中並沒有定義任務環境變量。
但是我搜索zsh找到的只有一個叫做「oh my zsh」的東西,我並沒有裝這個軟件
還有一種說法是修改.profile
文件,試過了,也沒用
最后我在Stack Overflow上找到了答案
https://stackoverflow.com/questions/15733508/why-do-i-need-to-source-bash-profile-every-time
Now that we've narrowed down the problem:
- Run
ps -p $$
at the command line to determine that you are, in fact, using a bash shell. - Realize that you are in zsh, which means you should be editing your profile in
.zshrc
. - Copy the offending lines from
.bash_profile
to.zsh
(注:個人認為這里是筆誤,應該是.zshrc
), OR Modify your.zshrc
to directly source your.bash_profile
.
在我的MacBook終端上執行ps -p $$
,發現結果是
PID TTY TIME CMD
692 ttys000 0:00.03 -zsh
雖然不知道是為什么會是zsh。但創建.zshrc
,把.bash_profile
的內容移動到.zshrc
,自此問題解決
后續,偶然看到一篇新聞,找到了問題的原因
在今年蘋果公司發布了macOS Catalina(10.15),macOS的默認終端從bash變成了zsh
也就是說只有在10.15之后的版本上才需要這樣配置