Tuesday 16 October 2007

ksh script template

Here's a nice little exampel of how to write and comment shell scripts.


#!/bin/ksh

#
#Display a usage message
#
usage() {
echo "usage: "
}

if [[ $# -lt 1 ]] ; then
usage
exit 1
fi

#
#Process command line options
#
while [ $# -gt 0 ]
do
case $1 in
-m) REGMODEL=$2
shift
;;
-t) REGTEST=$2
shift
;;
-p) REGPROTO=$2
shift
;;
-b) REGBLD=$2
shift
;;
-months) MONTHS_TO_Q=$2
shift
;;
-h) help=true
;;
-burt) BURT=1
;;
-graph) GRAPH=1
;;
-error) ERROR=1
;;
-all) ALL=1
;;
-*) echo $0 $1: Unrecognised option >&2
;;
*) ;;
esac
shift
done