首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

~/.bash_profile在某些情况上没有执行

2013-03-01 
~/.bash_profile在某些情况下没有执行下面是解释Opening a new terminal in X invokes bash as an interac

~/.bash_profile在某些情况下没有执行
下面是解释
Opening a new terminal in X invokes bash as an interactive shell, but not as a login shell. Therefore your ~/.bash_profile will not execute, but your ~/.bashrc should.
.bash_profile is only supposed to be run once, by the login shell. .bashrc is the file that's run for each child.
意思是,只有是interactive login shell(交互式登录终端)的情况下,才会执行~/.bash_profile,~/.bash_profile会调用~/.bashrc,看~/.bash_profile内容即知。
如果不是interactive login shell,例如启动X终端,或者ssh自动登录,这相当于启动了一个登录终端的child,只会执行~/.bashrc。


实验验证:
我是用putty登录的,用了ssh,启动时执行了screen。
在~/.bash_profile末尾加上
    echo bash_profile ran $(date)
在~/.bashrc末尾加上
    echo bashrc ran $(date)
重新用putty登录,得到
    .bashrc ran Wed Feb 27 09:34:40 CST 2013
看来,我登录的情况,只有~/.bashrc得到了执行。
更详细的解释,man bash 看INVOCATION 段。

热点排行