Start-Up Files#

When bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The –noprofile option may be used when the shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the –norc option. The –rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

~/.bash_profile#

Example of my ~/.bash_profile:

Listing 1 ~/.bash_profile#
1export BASH_SILENCE_DEPRECATION_WARNING=1
2export CLICOLOR=1
3export LSCOLORS=ExGxCxDxCxegedabagaced 
4
5if [ -f ~/.bashrc ]; then 
6    source ~/.bashrc 
7fi  
8
9eval "$(/opt/homebrew/bin/brew shellenv)"  

From the bash man page:

“When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option can be used when the shell is started to inhibit this behavior.”

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This can be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc

~/.bashrc#

Every new terminal window/tab that you open will load .bashrc

On a brand-new user account, none of these files will exist, they can be created with any suitable text editor that is capable of creating plain text files with Unix style (LF) line endings. Save them into your home folder (~/)

Example of my ~/.bashrc file contains:

Listing 2 ~/.bashrc#
1if [ -e ~/.bash_aliases ]; then 
2    source ~/.bash_aliases 
3fi 
4
5export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"

Aliases are shortcuts that can save you from having to remember long commands and eliminate a great deal of typing when you are working on the command line

~/.bash_aliases#

Example of my ~/.bash_aliases file:

Listing 3 ~/.bash_aliases#
 1# aliases
 2alias myconda='eval "$(/Users/van/Programs/miniforge3/bin/conda shell.bash hook)"; conda activate'
 3
 4# software
 5alias chimera="/Applications/Chimera.app/Contents/MacOS/chimera"
 6alias chimerax="/Applications/ChimeraX-1.5.app/Contents/MacOS/ChimeraX"
 7alias iqmol="/Applications/IQmol.app/Contents/MacOS/IQmol" 
 8alias vmd="/Applications/VMD\ 1.9.4.app/Contents/MacOS/startup.command"  
 9
10# rsync 
11alias rsyncnc='rsync -auvim --include "*/" --include "*/*nc" --exclude "*/*.*" --exclude "*/sinr*" --exclude "*/*/" --exclude "*/*" --exclude "*/*.out" --exclude "*/*.err"' 
12alias rsynccv='rsync -auvim --include "*/" --include "*/*cv" --exclude "*/*.*" --exclude "*/sinr*" --exclude "*/*/" --exclude "*/*" --exclude "*/*.out" --exclude "*/*.err"' 
13alias rsyncqm='rsync -auvim --exclude "*/qmhub/" --exclude "*/qmhub/*/" --exclude "*/qmhub/*/*"'