系统版本:

Red Hat Enterprise Linux Server release 6.2 (Santiago)


实验准备:

--------------
[root@db1 ~]# for file in /etc/profile /etc/profile.d/a.sh  ~/.bash_profile  ~/.bashrc /etc/bashrc;do touch $file;mv $file $file.bak ;echo ' echo   '$file'  load start @ `date +%S.%N`' >> $file; cat $file.bak >>$file;echo ' echo   '$file'  load finished @ `date +%S.%N`' >> $file;done

--------------


结果:

login shell:

[root@db1 ~]# su - root
/etc/profile load start @ 00.342533947
/etc/profile.d/a.sh load start @ 00.375653156
/etc/profile.d/a.sh load finished @ 00.386663719
/etc/profile load finished @ 00.459338038
/root/.bash_profile load start @ 00.472126516
/root/.bashrc load start @ 00.501099137
/etc/bashrc load start @ 00.517663430
/etc/bashrc load finished @ 00.530761110
/root/.bashrc load finished @ 00.548283973
/root/.bash_profile load finished @ 00.567944143


非login shell:

[root@db1 ~]# su root

/root/.bashrc load start @ 22.772783963
/etc/bashrc load start @ 22.785428207
/etc/profile.d/a.sh load start @ 22.801624494
/etc/profile.d/a.sh load finished @ 22.816499465
/etc/bashrc load finished @ 22.881630850

/root/.bashrc load finished @ 22.892364478


验证bash的配置文件加载顺序_第1张图片


图示:(时间重叠部分体现了相互调用关系)


验证bash的配置文件加载顺序_第2张图片