Getting Started with a Custom Configuration

Problem

You’d like to tweak your environment but aren’t quite sure where to start.

Solution

Here are some samples to give you an idea of what you can do. We follow the suggestion in Creating Self-Contained, Portable RC Files to keep customizations separate for easy back-outs and portability between systems.

For system-wide profile settings, add the following to /etc/profile. Since that file is also used by the true Bourne shell, be careful not to use any bash-only features (e.g., source instead of .) if you do this on a non-Linux system. Linux uses bash as the default shell for both /bin/sh and /bin/bash (except when it doesn’t, as in Ubuntu 6– 10+, which uses dash). For user-only settings, add it to only one of ~/.bash_profile, ~/.bash_login, or ~/.profile, in that order, whichever exists first:

# cookbook filename: add_to_bash_profile

# If we're running in bash, search for then source our settings
# You can also just hard code $SETTINGS, but this is more flexible
if [ -n "$BASH_VERSION" ]; then
    for path in /opt/bin /etc ~ ; do
        # Use the first one found
        if [ -d "$path/settings" -a -r "$path/settings" -a -x "$path/settings" ]
        then
            export SETTINGS="$path/settings"
        fi
    done
    source "$SETTINGS/bash_profile"
    #source "$SETTINGS/bash_rc"      # If necessary
fi

For system-wide environment settings, add the following to /etc/bashrc (or /etc/bash. bashrc):

# cookbook filename: add_to_bashrc # If we're running in bash, and it isn't already set, # search for then ...

Get bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.