.bashrc 未加载,.bash_profile 存在

rig*_*gyt 0 ubuntu bashrc rvm

在 ubuntu 终端中,直到运行以下命令后,我的 .bashrc 才可用: source ~/.bashrc

我有一个 ~/.bash_profile ,内容如下:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Run Code Online (Sandbox Code Playgroud)

我有一个 ~/.profile :

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi
Run Code Online (Sandbox Code Playgroud)

我应该怎么做才能自动加载我的 .bashrc?我应该合并 .bash_profile 和 .profile 并删除其中之一吗?谢谢

Cak*_*mox 5

您需要将您的文件中存在的相同逻辑添加.profile到您的.bash_profile. .profile如果存在则不会被使用.bash_profile,因此您的资源.bashrc不会被获取。

不过,在 .bash_profile 中不需要检查是否正在运行 bash。这就足够了:

[[ -f ~/.bashrc ]] && source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)