今天想 在 .bashrc 中配置一段自动启动 ssh-agent 的脚本,结果总是没有自动运行;才发现我的 bashrc 脚本没有自动 加载
后来才发现是这次装的深度系统(deepin)默认没有 ~.profile
脚本, 去看看之前的ubuntu系统里面都默认是有这个脚本的,而 ~.bashrc
脚本则是通过 .profile 来加载的
如果新建一个用户, 在其 $HOME 目录下会自动创建 .profile 脚本吗?
1. linux系统加载bash配置脚本的顺序
.bashrc 文件本身在 *nix 系统下就不会自动加载,一般都是通过 .profile 间接加载的
一般,系统会按下面的顺序加载
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
如果你的.bashrc
没有自动加载,就新建 ~/.profile
# ~/.profile: executed by Bourne-compatible login shells.
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi
mesg n
当然如果, 已经有了
.bash_profile
or.bash_login
, 那么这个.profile
文件也不会被加载。 总之,是把 此段代码写到 已经存在的 最先被加载到的那个配置中。
refer to :
http://askubuntu.com/questions/260682/bashrc-not-autosourced-in-12-04-lts
http://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically
2. Difference Between .bashrc & .bash_profile
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
当你直接在机器login界面登陆、使用ssh登陆或者su切换用户登陆时,.bash_profile 会被调用来初始化shell环境
Note:.bash_profile文件默认调用.bashrc文件当你不登陆系统而使用ssh直接在远端执行命令,.bashrc 会被调用
- 你已经登陆系统后,每打开一个新的Terminal时,.bashrc 都会被再次调用。
若要配置环境变量之类,最保险是写在 .bashrc 文件中。因为不管是登陆还是不登陆,该文件总会被调用
refer to :