關(guān)于登錄linux時(shí),/etc/profile、~/.bash_profile等幾個(gè)文件的執(zhí)行過程。
在登錄Linux時(shí)要執(zhí)行文件的過程如下: 在剛登錄Linux時(shí),首先啟動(dòng) /etc/profile 文件,然后再啟動(dòng)用戶目錄下的 ~/.bash_profile、 ~/.bash_login或 ~/.profile文件中的其中一個(gè),執(zhí)行的順序?yàn)椋簙/.bash_profile、 ~/.bash_login、 ~/.profile。如果 ~/.bash_profile文件存在的話,一般還會(huì)執(zhí)行 ~/.bashrc文件。因?yàn)樵?~/.bash_profile文件中一般會(huì)有下面的代碼: if [ -f ~/.bashrc ] ; then . ./bashrc fi ~/.bashrc中,一般還會(huì)有以下代碼: if [ -f /etc/bashrc ] ; then . /bashrc fi 所以,~/.bashrc會(huì)調(diào)用 /etc/bashrc文件。最后,在退出shell時(shí),還會(huì)執(zhí)行 ~/.bash_logout文件。 執(zhí)行順序?yàn)椋?etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout 關(guān)于各個(gè)文件的作用域,在網(wǎng)上找到了以下說(shuō)明: (1)/etc/profile: 此文件為系統(tǒng)的每個(gè)用戶設(shè)置環(huán)境信息,當(dāng)用戶第一次登錄時(shí),該文件被執(zhí)行. 并從/etc/profile.d目錄的配置文件中搜集shell的設(shè)置。 (2)/etc/bashrc: 為每一個(gè)運(yùn)行bash shell的用戶執(zhí)行此文件.當(dāng)bash shell被打開時(shí),該文件被讀取。 (3)~/.bash_profile: 每個(gè)用戶都可使用該文件輸入專用于自己使用的shell信息,當(dāng)用戶登錄時(shí),該文件僅僅執(zhí)行一次!默認(rèn)情況下,他設(shè)置一些環(huán)境變量,執(zhí)行用戶的.bashrc文件。 (4)~/.bashrc: 該文件包含專用于你的bash shell的bash信息,當(dāng)?shù)卿洉r(shí)以及每次打開新的shell時(shí),該該文件被讀取。 (5)~/.bash_logout:當(dāng)每次退出系統(tǒng)(退出bash shell)時(shí),執(zhí)行該文件. 另外,/etc/profile中設(shè)定的變量(全局)的可以作用于任何用戶,而~/.bashrc等中設(shè)定的變量(局部)只能繼承/etc /profile中的變量,他們是"父子"關(guān)系。 (6)~/.bash_profile 是交互式、login 方式進(jìn)入 bash 運(yùn)行的~/.bashrc 是交互式 non-login 方式進(jìn)入 bash 運(yùn)行的通常二者設(shè)置大致相同,所以通常前者會(huì)調(diào)用后者。 |
|