bashrc,bash_profile和/etc/profile

bashrc,bash_profile和/etc/profile

最近老出现在shell里面能跑的程序用鼠标双击app去不能跑.究其原因是因为环境变量的问题.

在类unix系统中一般有三个bash配置文件:

  • ~/.bashrc 当前用户使用的配置文件
  • ~/.bash_profile 当前用户使用的配置文件
  • /etc/profile 所有用户都会继承的环境配置文件

我们需要搞清楚/etc/profile, ~/.bash_profile和~/.bashrc这几个文件的加载顺序.

一般来说~/.bash_profile > ~/.bash_rc > /etc/profile, 也就是说当没有找到bash_profile则使用bashrc再没找到就用/etc/profile

有兴趣的可以参考这篇博文: http://blog.galeo.me/post/23467503436/path-environment-variable-on-mac-os-x-emacs-app

 

在MacOSX的shell中读取的是.bash_profile,而不读取.bashrc.有两个配置也挺让人头痛的,不过stackoverflow给出了解决方案

Terminal opens a login shell. This means, ~/.bash_profile will get executed, ~/.bashrc not. The solution on most systems is to „require“ the ~/.bashrc in the ~/.bash_profile: just put this snippet in your ~/.bash_profile:

[[ -s ~/.bashrc ]] && source ~/.bashrc
posted @ 2014-07-26 20:27  clivelee  阅读(294)  评论(0编辑  收藏  举报