.bashrc未加载,.bash_profile存在

在ubuntuterminal中,我的.bashrc在我运行之前是不可用的:source〜/ .bashrc

我有一个〜/ .bash_profile的内容:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* 

我有一个〜/ .profile:

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

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

您需要将.profile中存在的相同逻辑添加到.bash_profile 。 如果.bash_profile存在,那么.profile不会被使用,所以你的.bashrc不会被find。

但是,在.bash_profile中检查是否正在运行bash。 这已经足够了:

 [[ -f ~/.bashrc ]] && source ~/.bashrc 

SuperUser上有一个很好的答案,解释了.bashrc和.bash_profile之间的区别 。

本质上,“configuration文件”文件只能在login时读取。 你可以这样想, 当你login时,shell使用其中一个configuration文件来“设置你的configuration文件”。

否则,如果您已经login,并且您启动了一个新的会话(打开一个新的选项卡/窗口或在cli上调用bash),shell会读取您的“rc”文件。

我把大部分东西放在我的.bashrc文件中,然后从我的.profile文件中find.bashrc文件。 这里是一个例子:

我的.profile文件:

 source ~/.bashrc 

我的.bashrc文件:

 alias g='egrep -i' export CLICOLOR=1 export LSCOLORS=ehfxcxdxbxegedabagacad PS1="\[\e[0;31m\]\u\[\e[0;32m\]@\[\e[0;31m\]\h\[\e[0;37m\] \w\[\e[0;39m\]" case `id -u` in 0) PS1="${PS1}# ";; *) PS1="${PS1}$ ";; esac