.profile有语句调用.bashrc,但.bashrc没有执行

时间:2017-01-14 10:09:50

标签: bash ubuntu if-statement

我正在使用Ubuntu 16.04。在我的$HOME/.profile中,它有

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,最初有这些语句的目的是什么。

由于

1 个答案:

答案 0 :(得分:0)

(评论过得太长了:))

请参阅Ask Ubuntu上的this question.profile可能在sh下运行,而不是bash,因此BASH_VERSION中未设置.profile

要测试此功能,请添加

ps >> /tmp/testtmp.txt

.profile。您将看到正在运行的shell的进程名称,可能是每this个破折号。

要查看您的默认外壳grep <whatever your username is> /etc/passwd - 您会看到/bin/<whatever>sh

如果确实/bin/bash未设置为默认shell,则可以更改它(按this answer):

sudo chsh -s /bin/bash <whatever your username is>
相关问题