Configuring bash Startup Files on OS X

October 28, 2014 — Leave a comment

By default, OS X comes with a buggy implementation of bash startup files. Here’s my approach to configuring bash’s startup files:

Feel free to follow the steps below or enjoy this 12 minute video discussion:

Create .bash_profile in $HOME if .bash_profile doesn’t already exist and set its file permissions:

touch .bash_profile
chmod 755 .bash_profile

Edit .bash_profile to include any “bash specific” commands which will only work in bash, and not in other POSIX shells (zsh, etc.)

Create .profile in $HOME if .profile does exist and set its files permssions:

touch .profile
chmod 755 .profile

Call .profile from the end of .bash_profile by adding the following:

if [ -f ~/.profile ]; then 
        source ~/.profile 

Utilize .profile to include all modifications of PATH or any environment variables.

Create .bashrc in $HOME if .bashrc doesn’t exist and set its file permissions:

touch .bashrc
chmod 755 .bashrc

Add the following lines to .bashrc:

# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        source /etc/bashrc

Call .bashrc from the end of .profile by adding the following lines to .profile:

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

Use .bashrc for creating aliases and other functions which won’t pollute the the environment variable namespace with duplicate names etc. For good measure, include the following shell function, written by Gordon Davisson:

pathadd() {
    if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then

Use the following syntax when adding a directory, such /usr/bin to the PATH within .profile:

pathadd /usr/bin

Hopefully this configuration setup will promote good organization and express intentions clearly. Let me know if you come up with something better.

My best,




No Comments

Be the first to start the conversation.

I welcome your comments