它们都是脚本, 都会在登录系统时(第一层shell(barh))执行
/etc/profile、~/.bash_profile 只会在每次登录系统(顶层shell)时执行一次
/etc/bashrc、~/.bashrc 在每次创建子bash时都会触发
/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 都可用来配置环境变量 , 但作用域不同
/etc/profile、/etc/bashrc 是系统级别的
~/.bash_profile、~/.bashrc 是用户级别的
/etc/bashrc 是被 ~/.bashrc 调用的
而 ~/.bashrc 是被 ~/.bash_profile 调用的
~/.bash_profile 调用 ~/.bashrc 调用 /etc/bashrc
/etc/profile
用来设置系统环境参数,比如$PATH
对所有用户生效的。
cat /etc/profile
sudo vi /etc/profile
/etc/bashrc
设置bash相关的内容,
对系统内所有用户生效。
只要用户运行bash命令,那么这里面的东西就在起作用。
cat /etc/bashrc
sudo vi /etc/bashrc
~/.bash_profile
= $HOME/.bash_profile用来设置一些环境变量,功能和/etc/profile 类似,作用域只针对当前用户
~波浪号代表用户在/Home目录下的主文件夹
cat ~/.bash_profile
vi ~/.bash_profile
cat $HOME/.bash_profile
vi $HOME/.bash_profile
~/.bashrc
= $HOME/.bashrc作用类似于/etc/bashrc, 只是针对当前用户,不对其他用户生效。
~波浪号代表用户在/Home目录下的主文件夹
cat ~/.bashrc
vi ~/.bashrc
cat $HOME/.bashrc
vi $HOME/.bashrc
$HOME/.bash_profile 调用 $HOME/.bashrc 调用 /etc/bashrc
一个试验
在四个文件种分别加入 ------echo ‘该文件名’
然后登录系统,新开bash,新开sh
可看出: