SHELL指令碼攻略(學習筆記)--1.5 bash環境配置流程,--1.5bash

來源:互聯網
上載者:User

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.