The end of this document shows how to create executable programs that can be run transparently of the operating system used.
% chsh Old shell: xxxxxxxxxxxxxxx New shell: /local/bin/bash
Here are skeleton versions of both
#!/bin/sh export MANPATH=$HOME/man:/local/man:/local/man/pbm:/local/man/tcl:/usr/man export CDPATH=.:$HOME:$HOME/public_html:$HOME/bin: export EDITOR=/local/bin/emacs export VISUAL=$EDITOR export PAGER=/local/bin/less TERM=vt100 export TERM TERMCAP
#!/bin/sh export MANPATH=/usr/share/catman:/usr/share/man:/usr/catman:/usr/man:/usr/freeware/catman:$HOME/man export CDPATH=.:$HOME:$HOME/public_html:$HOME/bin:$HOME/temp:$HOME/public_html/classes export MSGVERB=text:action export NOMSGLABEL=1 export NOMSGSEVERITY=1 export PAGER=/usr/local/bin/less export TERM TERMCAP export TERMMODE=0
# find out what OS we're running under OS=`uname -s` if [ `echo $OS | grep "IRIX"` ]; then OS="IRIX" fi export OS # Load our environment (specific to the given OS) if [ -f $HOME/.environment.$OS ]; then source $HOME/.environment.$OS fi #--- load SunOS stuff now --------------------------------------------- if [ $OS = "SunOS" ]; then export OPENWINHOME=/usr/openwin export MINICOM="-c on" PATH="$PATH:/usr/X11/bin:/usr/andrew/bin:$OPENWINHOME/bin:/usr/games:." LESS=-MM eval tset PS1='[\h]\n[\t] \w\$: ' PS2='> ' if [ ! "$SHELL" = "/bin/ash" ]; then # ash doesn't have aliases alias net='term < /dev/modem > /dev/modem 2> /dev/null&' fi alias dir=ls alias h=history alias a=alias ignoreeof=10 export PATH DISPLAY LESS TERM PS1 PS2 ignoreeof umask 066 biff y HISTSIZE=32 MAILCHECK=60 fi #--- load IRIX stuff now --------------------------------------------- if [ "$OS" = "IRIX" ]; then PATH="/usr/local/bin:/usr/freeware/bin:/sbin:/usr/bin:/usr/bin/X11:/usr/bsd:/usr/etc:/usr/sbin:/usr/java/bin:.:$HOME/bin" LESS=-MM eval tset PS1='[\h]\n[\t] \w\$: ' PS2='> ' if [ ! "$SHELL" = "/bin/ash" ]; then # ash doesn't have aliases alias net='term < /dev/modem > /dev/modem 2> /dev/null&' fi alias dir=ls alias h=history alias a=alias ignoreeof=10 export PATH DISPLAY LESS TERM PS1 PS2 ignoreeof umask 066 HISTSIZE=32 MAILCHECK=60 fi #---- Stuff common to IRIX and SunOS --------------------------------- # (put here commands that work under both Operating Systems.
Assume that you have a program called hello.c and want a working copy for both machines. Compile it on grendel and call the executable hello.SunOS, and the one for hermite hello.IRIX. Then create a shell file called hello that will test which OS it is running under and will select the appropriate executable. With bash it looks like this:
#! /local/bin/bash
OS=`uname -s`
if [ `echo $OS | grep "IRIX"` ]; then
OS="IRIX"
fi
hello.$OS $@
That works pretty well! Note: if you have exported the variable $OS in your .bashrc file, then $OS will be part of your environment, and you can skip Lines 2 to 5 of the shell file above:
#! /local/bin/bash hello.$OS $@