3

I'm quite new to developing under OSX and assigned some aliases and other preferences in the ~/.profile initially, however it got quite big and messy after a while because I had a lot of Environment Variables to define too.

So I created a ~/.bashrc file (as you would on linux) and placed all my aliases and preferences there. However, since every instance of mac terminal is a login terminal, it doesn't read the .bashrc but just .profile...

So my solution was to place a source .bashrc at the bottom of ~/.profile and that does the job. So I'm wondering whether that is not good and if there is a better and cleaner way of doing that, since this is a bit of a hack?

2 Answers2

2

Most Linux distributions do this out of the box, but you'll want to make sure your .bashrc is still only run by Bash in interactive shells.

Therefore you should guard the inclusion with a line like this:

[ "$BASH_VERSION" ] && [[ $- == *i* ]] || return
. "${HOME}/.bashrc"
Giacomo1968
  • 58,727
Bachsau
  • 152
2

See here in this answer from Stack Overflow. Chart below quoted for easy reference.

It's okay to add source ~/.bashrc to ~/.profile.

                     +-----------------+   +------FIRST-------+   +-----------------+
                     |                 |   | ~/.bash_profile  |   |                 |
login shell -------->|  /etc/profile   |-->| ~/.bash_login ------>|  ~/.bashrc      |
                     |                 |   | ~/.profile       |   |                 |
                     +-----------------+   +------------------+   +-----------------+
                     +-----------------+   +-----------------+
                     |                 |   |                 |
interactive shell -->|  ~/.bashrc -------->| /etc/bashrc     |
                     |                 |   |                 |
                     +-----------------+   +-----------------+
                     +-----------------+
                     |                 |
logout shell ------->|  ~/.bash_logout |
                     |                 |
                     +-----------------+
Giacomo1968
  • 58,727
dofine
  • 408
  • 1
  • 4
  • 8