Configuring bash to work with multiple systems

CSE users will generally have home directories on GPFS, shared to the different systems they work on (for example, the iDataplex and POWER7 systems). As different systems may not have the same OS, or the same version of OS, or the same tools, you will probably find that your environment doesn't get set up correctly on each system. One way to get around this is to point all other login files (~/.profile, ~/.bash_login, ~/.bash_profile) to ~/.bashrc, and using a simple if clause to apply system-specific configuration in ~/.bashrc. Note that general environment stuff may be setup in /etc/profile, /etc/bashrc and some or all of the scripts in /etc/profile.d, so before you do anything you might want to start with empty login files and do a few tests to decide exactly what local configuration, if any, you need.

Before you do anything, be sure to take backups of ~/.profile, ~/.bash_login, ~/.bash_profile and ~/.bashrc.

Edit each of ~/.profile, ~/.bash_login, and ~/.bash_profile to include the single line:

. ~/.bashrc

Then in ~/.bashrc, do something like this:

# Dave's .bashrc
# Set my prompts
export PS1='`hostname`:`pwd` $ '
export PS2='> '
# Ok, so let's find out which type of system I'm on.
OS=`uname`
if [ "${OS}" = "AIX" ]
        # This is AIX, so we need to know where the IBM compilers are
        # and ls doesn't support -h
        then export PATH=$PATH:/bin:/usr/vac/bin
        alias l='ls -lart'
        # Put other customisations here if you need them
elif [ "${OS}" = "Linux" ]
        # This is Linux, so ls supports -h
        then alias l='ls -larth'
        # Put other customisations here if you need them
else
        echo "I don't know what OS you're on, so I'm not doing any system localisation."
fi

if [ -s "$MAIL" ]           # This is at Shell startup.  In normal
then echo "$MAILMSG"        # operation, the Shell checks
fi                          # periodically.

alias h='history'

Note that I've used uname to test for the OS; you may wish to test for hostname instead. Obviously you can put your own customisations into the if clauses.

Configure_bash (last edited 2011-06-23 12:55:24 by DaveCable)

This website maintained by Research Computing Services, University of Manchester