linux bashrc vs profile - msforest/notebook GitHub Wiki
bashrc vs profile
作用
环境变量即可设置本地设置,也可全局设置;文件名都很类似,bashrc/profile
本地环境变量设置
# ~/.bashrc: executed by bash for non-login shells.
# ~/.profile: executed by Bourne-compatible login shells.
全局环境变量设置
# /etc/bashrc
# /etc/profile
- bashrc 是在系统启动后执行
- profile 是在用户登录后执行
source .bashrc
用于更新修改后的 bashrc 文件,bash .profile
用于更新修改后的 profile 文件
都是设置环境变量的目的,为啥会存在两个文件呢?
login shell / non-login shell不同点
区分两个文件存在的目的,要明白login shell
和non-login shell
, 字面意思已经很明确,是否需要在登录信息的命令下执行。如何判断当前 shell 是登录还是未登录,如下:
~$ echo $0
-bash # "-" is the first character. Therefore, this is a login shell.
~$ echo $0
bash # "-" is NOT the first character. This is NOT a login shell.
参考资料