Linux 環境變數配置

來源:互聯網
上載者:User

標籤:

linux 環境,使用者通過shell 操作時,系統會為使用者初使化環境變數, 比如系統公用資源路徑: path , include , bin 等目錄。 shell 模式下,執行 export , 查看使用者環境變數 , echo $key 查詢某個環境變數。

設定環境變數,有兩種方式,分為臨時設定,與永久設定。
a.臨時設定(即時生效)
shell 模式執行:
export PATH="$PATH:/opt/au1200_rm/build_tools/bin"

b.永久設定
#行尾追加 export...
vi /etc/profile
export PATH="$PATH:/opt/au1200_rm/build_tools/bin"

vi /root/.bashrc
export PATH="$PATH:/opt/au1200_rm/build_tools/bin"

以上幾種方式可以看出,設定環境變數的過程是一致的。shell 模式,直接執行指令碼,將環境變數匯入記憶體中,因此即時生效,其它的shell環境 無法使用該環境變數(隔離性)。 永久設定,在/etc/profile  , /root/.bashrc 檔案尾追加 export key="value" 這兩個檔案是使用者開啟shell 用戶端時,自動執行,其中/root/.bashrc 的優先順序高於/etc/profile 。 可做如下測試:

vi /etc/profile
export TEST="test1"

vi /root/.bashrc
export TEST="$TEST:test2"

在新的shell 模式下輸入 export , 結果:
declare -x TEST="test1:test2"

因此 /etc/profile  指令碼先於 /root/.bashrc 初使化,後者可以覆蓋前者。


參考資料
http://blog.csdn.net/bailyzheng/article/details/7488769

Linux 環境變數配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.