mac终端每次启动都要执行 source ~/.bash_profile


网上说法都是

发现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:

  1. Run ps -p $$ at the command line to determine that you are, in fact, using a bash shell.
  2. Realize that you are in zsh, which means you should be editing your profile in .zshrc.
  3. Copy the offending lines from .bash_profile to .zsh(注:个人认为这里是笔误,应该是.zshrc), OR
  4. 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之后的版本上才需要这样配置


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM