SHELL指令碼攻略(學習筆記)--1.5 bash環境配置流程,--1.5bash
站在使用者登入的角度來說,shell分為兩種類型:
登入式shell:如通過某終端登入,使用su - username命令切換使用者。
非互動式shell:如使用su username命令切換使用者;圖形終端下開啟命令終端;shell指令碼。
更簡單但不精確的區分方法是:不需要輸入帳號密碼才能登陸的shell的都是非互動式shell,如子shell、指令碼shell、圖形終端下開啟的命令視窗,但su username除外。
bash的環境設定檔:
全域配置:/etc/profile、/etc/profile.d/*.sh、/etc/bashrc。
個人配置:~/.bash_profile、~/.bashrc。
讀取和執行這些環境設定檔是有順序的,如果設定有衝突,則後讀取的設定檔覆蓋先讀取的。
讀取設定檔流程:
登入式shell讀取環境設定檔的順序是:
(1)/etc/profile-->/etc/profile.d/*.sh
(2)~/.bash_profile-->~/.bashrc-->/etc/bashrc
即先讀取全域設定檔/etc/profile,再讀取使用者設定檔~/.bash_profile。但/etc/profile檔案會調用/etc/profile.d/目錄下的所有.sh檔案,~/.bash_profile會調用~/.bashrc檔案,~/.bashrc又會調用/etc/bashrc檔案。其實/etc/bashrc還會調用/etc/profile.d/*.sh,但不會重複設定已設定過的選項。
非登入式shell讀取環境設定檔的順序是:
~/.bashrc-->/etc/bashrc-->/etc/profile.d/*.sh
也就是說:
/etc/profile:任意使用者登陸時讀取。非登入式shell不會讀取。
~/.bash_profile:對應使用者登陸時讀取,用以配置將要開啟的bash shell。非登入式shell不會讀取。
~/.bashrc:關於bash shell的配置,對應的使用者每次開啟一個shell都會讀取該檔案,因為登入式或非登入式shell都會讀取該檔案。
/etc/bashrc:(所有使用者)每次開啟一個shell(登入式或非登入式)都會讀取該檔案。
回到系列文章大綱:http://www.cnblogs.com/f-ck-need-u/p/7048359.html
轉載請註明出處:http://www.cnblogs.com/f-ck-need-u/p/7229025.html