Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux 程式設計 >> Shell 程式設計

登入shell與非登入shell:啟動腳本載入順序的差別

善用啟動腳本,能讓自訂環境一勞永逸。這些腳本在shell被建立時執行,而依shell是「登入」還是「非登入」,所載入的腳本也不同。

簡單記法:「su -」是登入shell;「su」是非登入shell。

放在啟動腳本中的典型內容包括:

① 本地變數設定,尤其是PS1(例如我的 export PS1='[\u@10gR2 \W \$]')。
② 環境變數,例如PATH。
③ 別名(alias)。
④ umask。

登入shell

/etc/profile 是登入shell啟動後執行的第一個腳本,只有登入shell才會觸發它。載入順序為:

/etc/profile → /etc/profile.d → .bash_profile → .bashrc → /etc/bashrc

每個被呼叫的腳本會依序覆蓋前一個的變更。若要處理登出時的任務(如自動備份、清除暫存檔),可寫進 .bash_logout。

非登入shell

載入順序為:

.bashrc → /etc/bashrc → /etc/profile.d

理解這兩者的差異,才能把環境變數放到正確的腳本裡。

Copyright © Linux教程網 All Rights Reserved