當我啟動 bash 終端時,.profile 未執行

當我啟動 bash 終端時,.profile 未執行

當我啟動 bash 終端時,我的 .profile 沒有被執行。我沒有 ~/.bash_profile 或 ~/.bash_login,所以 .profile 應該運行,對嗎?還有什麼可能是錯的?

答案1

它不是登入 shell。

如果 shell 是登入 shell,它將尋找 .bash_profile(如果存在),然後尋找 .profile。其他 shell 尋找 .bashrc

因此,您可以將您想要的內容放入 .bashrc 中的每個 shell 實例中,並且可能在 .profile 中提供來源 .bashrc 的參考。

所以:.bashrc:

stuff you want

.profile 結尾:

[ -n "$BASH" ] && [ -f ~/.bashrc ] && . ~/.bashrc

答案2

嘗試使用~/.bashrc代替。

答案3

如果您使用圖形桌面,.profile 應由您的桌面管理器取得。光DM現在就可以取得 .profile 的原始碼了,至少在 Ubuntu 上是這樣。看:https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/794315

使用 kdm 和 Kubuntu-12.04,可以取得檔案 /etc/kde4/kdm/Xsession,其中包含 .profile。 Kubuntu-12.10 可能會使用 lightdm。 Ubuntu 12.04 使用 lightdm,以便 /usr/sbin/lightdm-session 來源 .profile。

我認為要走的路是(1)在〜/ .profile中設置/導出環境設置,(2)由.bash_profile獲取.profile:

[[ -f ~/.profile ]] && . ~/.profile

(且沒有 .bashrc 源自 .profile 或 .bash_profile)。

也可以看看:

相關內容