0

In a ubuntu terminal my .bashrc isn't available until I run: source ~/.bashrc

I have a ~/.bash_profile with contents:

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

I have a ~/.profile with:

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

What should I do for my .bashrc to be loaded automatically? Should I merge .bash_profile and .profile and delete one of them? Thanks

2 Answers 2

5

You'll need to add the same logic that exists in your .profile to your .bash_profile. .profile isn't used if .bash_profile exists, so your .bashrc isn't being sourced.

The check for whether you're running bash is not necessary in .bash_profile, though. This is sufficient:

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

There is a great answer on SuperUser that explains the difference between .bashrc and .bash_profile.

Essentially, the "profile" files are only read at login. You can think of it this way; when you login, the shell uses one of the profile files to "setup your profile".

Otherwise, if you are already logged in, and you initiate a new session (open a new tab/window or invoke bash on the cli), the shell just reads your "rc" file.

I handle this by putting most everything in my .bashrc file and then sourcing the .bashrc file from my .profile file. Here is an example:

My .profile file:

source ~/.bashrc

My .bashrc file:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .