
bash
除非我從終端手動運行,否則不會.bashrc
從互動終端獲取來源:bash
$ bash
或手動獲取它:
$ source ./.bashrc
或運行:
$ st -e bash
我希望這是一些有用的輸出:
$ echo $TERM
st-256color
$ echo $SHELL
/bin/sh
$ readlink /bin/sh
bash
$ shopt login_shell
login_shell off
我使用的是 CRUX Linux 3.0,並且使用dwm
和st
。我嘗試過使用.bash_profile
但.profile
沒有成功。
有任何想法嗎?
答案1
在 .bash_profile 中,請確保您具有以下內容:
# .bash_profile
# If .bash_profile exists, bash doesn't read .profile
if [[ -f ~/.profile ]]; then
. ~/.profile
fi
# If the shell is interactive and .bashrc exists, get the aliases and functions
if [[ $- == *i* && -f ~/.bashrc ]]; then
. ~/.bashrc
fi
答案2
為什麼它會來源?您的預設 shell 不是 bash,而是sh
:
$ echo $SHELL
/bin/sh
在大多數現代系統中,sh
是基本 shell 的符號連結。以我的 Debian 為例:
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Aug 1 2012 /bin/sh -> dash
在您的情況下,sh
是一個連結到bash
但是,如下所述man bash
:
如果使用 sh 名稱呼叫 bash,它會盡量模仿 sh 歷史版本的啟動行為,同時也符合 POSIX 標準。 [...] 當作為名為sh 的互動式shell 呼叫時,bash 會尋找變數ENV,如果定義了該變量,則擴展其值,並使用擴展後的值作為要讀取和執行的檔案的名稱。自從作為 sh 呼叫的 shell 不會嘗試從任何其他啟動檔案讀取和執行命令,--rcfile 選項無效。
和
--norc
如果 shell 是互動的,則不要讀取和執行系統範圍的初始化檔案 /etc/bash.bashrc 和個人初始化檔案 ~/.bashrc。 如果 shell 以 sh 調用,則預設啟用此選項。
因此,由於您的預設 shell 是sh
,.bashrc
不會被讀取。只需使用 .bashrc 將預設 shell 設定為 bash 即可chsh -s /bin/bash
。