[教學]環境變數設定的考量 因常常對這類的問題有疑問,搞不清楚,故將找到的答案轉貼出來以供參考 在 bash 的 info pages 內提到: * 如果 bash 是交談式,且為 login shell (例如從虛擬控制台(文字模式的終端機)登入時所啟動的 shell)時,bash 會 (1) 先執行 /etc/profile, (2) 依 ~/.bash_profile, ~/.bash_login, ~/.profile 的順序搜尋,執行第一個存在的檔案。 * 若 bash 是交談式,但不是 login shell (例如由 gdm 圖形介面登入,再執行如 gnome-terminal, 或 rxvt 等 終端機模擬程式產生 shell 視窗) 時, bash 僅去讀取 ~/.bashrc RedHat 預設的 .bash_profile 內有 if [ -f ~/.bashrc ]; then . ~/.bashrc fi 代表若 ~/.bashrc 存在則執行該檔。 而在 .bash_profile 內則有 if [ -f /etc/bashrc ]; then . /etc/bashrc fi 代表若 /etc/bashrc 存在則執行該檔。 您可以把設定加在 ~/.bashrc 的檔案結尾,但需確認 ~/.bash_profile 在 if [ -f ~/.bashrc ]; then . ~/.bashrc fi 後是否有其他指令會蓋掉你在 .bashrc 內的設定。