【.bash_profile 与 .bashrc 的区别】

来源:互联网 发布:photoshopcs6 mac破解 编辑:程序博客网 时间:2024/06/05 16:53
【.bash_profile 与 .bashrc 的区别】
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

【login shell 与 non-login shell 的区别】
1、当你直接在机器login界面登陆、使用ssh登陆或者su切换用户登陆时,.bash_profile 会被调用来初始化shell环境
Note:.bash_profile文件默认调用.bashrc文件
.bash_profile中有如下内容
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi 
2、当你不登陆系统而使用ssh直接在远端执行命令,.bashrc 会被调用
3、当你已经登陆系统后,每打开一个新的Terminal时,.bashrc 都会被再次调用。

【故若要配置环境变量之类,最保险是写在 .bashrc 文件中。因为不管是登陆还是不登陆,该文件总会被调用!

~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该 
文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件. 

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 
并从/etc/profile.d目录的配置文件中搜集shell的设置. 


/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.




0 0