#!/bin/sh # MonthToNumeric.sh # Mon Jul 28 21:32:25 GMT 2008 # Chieh Cheng # http://www.CynosureX.com/ # GNU General Public License (GPL) Version 2, June 1991 scriptName=`basename "$0"` toNumeric () { str="$1" length=`StrLen.sh "${str}"` if [ ${length} -gt 3 ] then tmp=`SubStr.sh "${str}" 0 3` str="${tmp}" fi m=`echo "${str}" | tr '[A-Z]' '[a-z]'` case ${m} in jan) result="01";; feb) result="02";; mar) result="03";; apr) result="04";; may) result="05";; jun) result="06";; jul) result="07";; aug) result="08";; sep) result="09";; oct) result="10";; nov) result="11";; dec) result="12";; *) result="99";; # *) reportError "Bad month: ${m}!"; result="99";; esac return "${result}" } usage () { echo " Usage: ${scriptName} [ -p ] \"Month in Three or More Letters\"" echo echo " -p Pad leading zero." } padZero=0 if [ $# -eq 2 ] then if [ "$1" = "-p" ] then padZero=1 shift fi fi if [ $# -eq 1 ] then month="$1" toNumeric "${month}" num=$? if [ ${num} -lt 10 -a ${padZero} -eq 1 ] then echo "0${num}" else echo ${num} fi else usage fi