执行顺序
- /etc/profile
- ~/.bash_profile
- ~/.bashrc
- ~/.bash_login
- ~/.profile
- ~/.bash_logout
功能:
- 提示符
- 别名
- 函数
- 路径
作用域及优先级:
文件 | 路径 | 作用域 | 执行 | 优先级 |
---|---|---|---|---|
Profile | /etc/profile | 全局 | 启动执行一次 | 1 |
Profile | ~/.profile | 单用户 | login执行一次 | 3 |
bash_profile | ~/.bash_profile | 单用户 | login执行一次 | 2 |
bashrc | /etc/bashrc | 全局 | bash shell / script 每次 | 4 |
bashrc | ~/.bashrc | 单用户 | bash shell / script 每次 | 5 |
- 首先读入全局环境变量设定档
/etc/profile
,然后根据其内容读取额外的设定的文档,如/etc/profile.d
和/etc/inputrc
; - 根据不同使用者帐号,于其
home
目录内读取~/.bash_profile
; 读取失败则会读取~/.bash_login
; 再次失败则读取~/.profile
; - 最后,一般会在
~/.profile
或~/.bash_profile
文件中显式调用~/.bashrc
。 - 至于
~/.profile
与~/.bashrc
都具有个性化定制功能,但~/.profile
可以设定本用户专有的路径、环境变量等,它只能登入的时候执行一次。
~/.bashrc
也是某用户专有设定文档,可以设定路径、命令别名,每次shell script的执行都会使用它一次。