Linux 下 Bash配置文件读取

 Linux安装时可能要修改的配置文件:/etc/profile、/etc/bashrc(ubuntu没有这个文件,对应地,其有/etc/bash.bashrc文件。我用的是ubuntu系统,所以下面将一律使用/etc/bash.bashrc来叙述)、~/.bash_profile、~/.bash_login、~/.profile、~/.bashrc。

utuntu系统默认只有/etc/profile、/etc/bash.bahsrc、~/.profile、~/.bashrc这四个文件。其他文件可以创建。

1  /etc/profile

用于设置系统级的环境变量和启动程序

2  ~/.profile

该文件是一个用户级的设置,这个文件同样也可以用于配置环境变量和启动程序,但只针对单个用户有效

3  ~/.bashrc和/etc/bashrc(/etc/bash.bahsrc)

这个两个文件用于配置函数或别名,/etc/bashrc是系统级的、~/.bashrc是用户级的,两者分别会对所有用户和当前用户生效。

读取顺序:

  在4个文件中加入 echo 语句测试

切换管理员

eko@ubuntu:~$ su -
Password: 
here is /etc/bash.bashrc
here is /etc/profile

切换用户

root@ubuntu:~# su - 'eko'
here is /etc/bash.bashrc
here is /etc/profile
here is /eko/.bashrc
here is /eko/.profile

可见登录式Shell执行顺序是:

  /etc/.bashrc --> /etc/profile -->  ~/.bashrc --> ~/.profile

非登录式Shell

eko@ubuntu:~$ su
Password: 
here is /etc/bash.bashrc

  

root@ubuntu:/home/eko# su 'eko'
here is /etc/bash.bashrc
here is /eko/.bashrc

  /etc/bash.bashrc --> ~/.bashrc

猜你喜欢

转载自www.cnblogs.com/xiaoliwang/p/8983498.html