和用户登录相关的文件

   

用户登录是需要读取的文件

1、/etc/profile

2、/etc/bashrc

3、/etc/profile.d/*

4、~user/.bashrc

5、~user/.bash_profile


登录shell和非登录shell:

[root@localhost ~]# su - usr4登录shell

[root@localhost ~]# su usr4非登录shell

非登录shell使用的是别人的环境变量


演示登录shell和非登录shell执行了哪些文件

在以下4个文件的最前和最后分别加上

[root@localhost profile.d]# vim /etc/profile

echo "/etc/profile begin"

echo "/etc/profile end"

[root@localhost profile.d]# vim /etc/bashrc

echo "/etc/bashrc begin"

echo "/etc/bashrc end"

[root@localhost profile.d]# vim /home/usr4/.bashrc

echo "/home/usr4/.bashrc begin"

echo "/home/usr4/.bashrc end"

[root@localhost profile.d]# vim /home/usr4/.bash_profile

echo "/home/usr4/.bash_profile begin"

echo "/home/usr4/.bash_profile end"

[root@localhost profile.d]# pwd

/etc/profile.d

[root@localhost profile.d]# vim test.sh

#! /bin/bash

echo "/etc/profile.d"

验证登录shell和非登录shell执行的文件有何区别?

登录shell

[root@localhost usr4]# su - usr4

/etc/profile begin

/etc/profile.d

/etc/profile end

/home/usr4/.bash_profile begin

/home/user4/.bashrc begin

/etc/bashrc begin

/etc/bashrc end

/home/usr4/.bashrc end

/home/usr4/.bash_profile end

非登录shell

[root@localhost usr4]# su usr4

/home/usr4/.bashrc begin

/etc/bashrc begin

/etc/profile.d

/etc/bashrc end

/home/usr4/.bashrc end