我使用的是Ubuntu 16.04。在我的$HOME/.profile
,它具有.profile有聲明調用.bashrc,但.bashrc不執行
echo `date` ':.profile executed starts' >> /tmp/testtmp.txt
echo $BASH_VERSION >> /tmp/testtmp.txt
if [ -n "$BASH_VERSION" ]; then
echo 'if 1 entered' >> /tmp/testtmp.txt
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
echo 'if 2 entered' >> /tmp/testtmp.txt
. "$HOME/.bashrc"
fi
else
echo 'if 1 not entered' >> /tmp/testtmp.txt
fi
我每次登錄,它甚至從來沒有達到第一IF
。
測試文件顯示:
Sat Jan 14 05:15:57 EST 2017 :.profile executed starts
if 1 not entered
Sat Jan 14 05:15:57 EST 2017 :.profile executed ends
我贊同$ BASH_VERSION,它顯示4.3.46(1)-release
。所以如果if [ -n "$BASH_VERSION" ]
是爲了檢查變量是否存在,(顯然是),爲什麼它甚至沒有達到第一個IF?
從結果看來,直到我第一次調用終端應用程序時,纔會生成$ BASH_VERSION。
由於.profile中的那些IF語句是原創的,我不明白如果在登錄時沒有生成$ BASH_VERSION,那麼最初擁有這些語句的目的是什麼。
感謝
你怎麼知道它永遠不會到達第一個'if'聲明?另外,是不是正在執行的'.profile'或'.bashrc'?你的頭銜說一個,但身體說另一個。 –
你是怎麼稱呼.profile文件的?使用'source〜/ .profile'?還有,你在哪裏回覆了$ BASH_VERSION –
抱歉的傢伙。我更新了我的問題。 –