.bashrc Should be Your Playground, Leave .bash_profile Alone.

On Unix-based systems like macOS, we usually interact with the 'shell' quite often. One of the most common tasks is issuing repetitive commands to perform tasks at the commandline. To remove the tediousness, we often like to customize how 'bash' or some other shell behaves. These customizations go either into '.bashrc' or '.bash_profile' in the user's home directory.

Commands in '.bash_profile' however are run only on user login (or precisely, when a user launches a new terminal window). One of the best practices is to put your customizations into a file called '.bashrc' in your home directory (signified by '~'). And then load '.bashrc' from '.bash_profile'.

Here is how it's done:

1. Check for the file's presence in your home directory...

$ ls -la ~ | grep .bashrc

Or just do this and visually inspect the listing to spot the file.

$ cd ~
$ ls -la

2. If the file is not present, create it like so:

$ cd ~
$ touch .bashrc

3. Load '.bashrc' into '.bash_profile' dynamically:

$ vi ~/.bash_profile


if [ -f ~/.bashrc ]; then
  source ~/.bashrc
fi

4. Now put your custom configurations in '.bashrc' and they will always be read in.

One of the common repetitive thing you may want to put there is reloading '.bashrc' without closing the terminal

Open '.bashrc' and add this line:

alias src='source ~/.bashrc'