linux下.bashrc为什么每次打开终端都要source一下才有效,如何才能永远生效?

发布网友

我来回答

3个回答

热心网友

终端:
vi ~/.bash_profile

在.bash_profile文件的最末尾上加入如下语句:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

保存。
这个我试过了可以。这样改了.bash_profile以后,只要运行一次 source .bash_profile就一劳永逸了。就不需要每次打开terminal每次运行source .bashrc了。

热心网友

在当前用户目录,增加一个.profile文件,增加以下内容

# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

热心网友

换个地方写吧,网搜一下即可,这个配置文件不是开机生效的,是临时生效,所以才要source一下。具体在哪个配置文件写我就忘了,搜一下就行。

热心网友

终端:
vi ~/.bash_profile

在.bash_profile文件的最末尾上加入如下语句:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

保存。
这个我试过了可以。这样改了.bash_profile以后,只要运行一次 source .bash_profile就一劳永逸了。就不需要每次打开terminal每次运行source .bashrc了。

热心网友

在当前用户目录,增加一个.profile文件,增加以下内容

# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

热心网友

换个地方写吧,网搜一下即可,这个配置文件不是开机生效的,是临时生效,所以才要source一下。具体在哪个配置文件写我就忘了,搜一下就行。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com