不知何故,我的 bash 提示字元更改為“elementary:~ steven$”,我想將其更改回預設提示符號。我首先將以下內容新增至 ~/.bashrc 然後新增至 ~/.profile:
export PS1="\s-\v\$ "
當我打開終端時,兩者都不會被執行。如果我在任一文件上執行該命令,source它在該會話的其餘部分中都可以正常工作。
我在這裡忽略了什麼嗎?
編輯:這是伊恩建議的輸出:
elementary:~ steven$ bash --login --verbose
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
/usr/libexec/path_helper -s
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/usr/local/AVRMacPack/bin"; export PATH;
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
return
fi
PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
if [ -e "/usr/local/AVRMacPack" ]; then
PATH="$PATH:/usr/local/AVRMacPack/bin"
export PATH
fi
# Setting PATH for Python 3.2
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.2/bin:${PATH}"
export PATH
elementary:~ steven$ which bash
which bash
/bin/bash
答案1
.bashrc根據 bash 手冊頁,僅對非互動式 shell 執行。
.bash_profile針對登入 shell 執行。
該.profile檔案由 Korn shell 載入。我不知道bash根本不關心這個。我在 bash 手冊頁中找不到任何對它的引用。
在 OS X 上,Terminal.app 程式會為您開啟的每個新 Terminal.app 視窗執行一個登入 shell。
所以你想把你的提示設定放在.bash_profile.
您始終可以在.bash_profile.這並不罕見,但我不能說它會產生什麼樣的影響:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
那麼您就不必維護兩個文件。
答案2
我可能是不正確的,但如果 bash 是你的 shell,你必須將其放在你的 ~/.bash_profile 而不是你的 .bashrc 中。
答案3
如果你搞亂了你的bash控制無論出於何種原因,您想要加載您的終端。再次在每個會話中,只需寫下您的〜/ .bash_profile像這樣:
if [ -f ~/.profile ]; then
source ~/.profile
fi
...並開始一個新會話以檢查一切是否恢復正常


