# SccsId[] = "%W% (USL function) %G%"
              M2N_name="MONTH_MMM_TO_NN"
              if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
                 [ ."`set|egrep '^$M2N_name\(\)\{$'`" != . ] && M2N_loaded=1
              else # Korn or Bash shell and function already loaded?
                 if [ `expr "\`uname -s\`" : "[Ll][Ii][Nn][Uu][Xx]"` -eq 0 ]; then
                    [ ."`typeset +f|awk '/^'$M2N_name'[=\(]?/'`" != . ] && M2N_loaded=1
                 else # Linux
                    [ ."`typeset -F|awk '/^'$M2N_name'[=\(]?/'`" != . ] && M2N_loaded=1
                 fi
              fi
              if [ 0${M2N_loaded} -eq 0 ]; then
              #----------------------------------------------------------------------#
              MONTH_MMM_TO_NN() # Function documentation located at bottom.          #
              #----------------------------------------------------------------------#
              { [ ."${AWK}" = . ] && { { [ -x /usr/bin/nawk ] && AWK=/usr/bin/nawk; } \
                                  ||   { [ -x /bin/gawk     ] && AWK=/bin/gawk    ; } \
                                  ||   { [ -x /usr/bin/awk  ] && AWK=/usr/bin/awk ; }; }

                if [ $# -gt 0 ]; then
                   $AWK    \
                    'BEGIN \
                     {
                       mon_table = "jan01feb02mar03apr04may05jun06" \
                                   "jul07aug08sep09oct10nov11dec12"
                       mon_idx   = index(mon_table,tolower(ARGV[1]))
                       if (mon_idx < 1)
                       {
                         printf("Invalid Month: %s\n", ARGV[1])
                         exit 0
                       }
                       mm = sprintf("%02d", substr(mon_table,mon_idx+3,2))
                       print mm
                       exit  mm
                     }' $1
                   return $?
                fi

                #------------------------------------------#
                # Reaching here means something is amiss.  #
                #------------------------------------------#
                if [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi

                . $SHLIB/email_msg.sh # Calls $SHLIB/exit.sh

                #------------------------------------------------------------#
                # If the following variables are not set, use these defaults.#
                #------------------------------------------------------------#
                : ${script_name:=`basename $0`}
                : ${sp:="                    "}

                M2N_ID="$script_name($M2N_name)"

                EMAIL_MSG "ERROR (Function): $M2N_ID"                   \
                  "${sp}Usage:   $M2N_name Mmm"                         \
                  "${sp}         Mmm is abbreviated month (Jan-Dec)."   \
                  "${sp}Purpose: Convert abbreviated month name to its" \
                  "${sp}         two-digit month number."
                return 0
              } # "M2N_" prefix identifies this function's local variables.
              fi

              #======================================================================#
              #                       D O C U M E N T A T I O N                      #
              #======================================================================#
              #                                                                      #
              #      Author: Bob Orlando                                             #
              #                                                                      #
              #        Date: April 29, 1998                                          #
              #                                                                      #
              #  Program ID: month_mmm_to_nn.sh                                      #
              #                                                                      #
              #       Usage: MONTH_MMM_TO_NN Mmm                                     #
              #                        where Mmm is a month name (Jan-Dec)           #
              #                                                                      #
              #     Purpose: Convert abbreviated month name to a two-digit           #
              #              month number.                                           #
              #                                                                      #
              # Description: Echos and returns a valid two-digit month number        #
              #              appropriate to the month name abbreviation passed,      #
              #              or echos and returns zero on error (an invalid month    #
              #              number).  The user can capture stdout or use the        #
              #              this function's return status for the month number.     #
              #                                                                      #
              #     Globals: No global variables assigned from this function.        #
              #              "M2N_" prefix identifies local function variables.      #
              #                                                                      #
              #       Calls: EMAIL_MSG library function (on error).                  #
              #                                                                      #
              # Exit_status: 1-12 for success                                        #
              #              Zero on error.                                          #
              #                                                                      #
              #       Notes: My biggest reason for writing this function is simply   #
              #              to have this code/method written down somewhere.  Its   #
              #              essence is an echo of the month table (MmmNnMmmNn...)   #
              #              through a sed that extracts the month number (Nn) that  #
              #              immediately follows the abbreviated month (Mmm).        #
              #                                                                      #
              #    Modified: 2004-04-02 Bob Orlando                                  #
              #                 v1.9  * Expand $AWK testing and assignment.          #
              #                                                                      #
              #              2004-03-03 Bob Orlando                                  #
              #                 v1.8  * Change set|egrep|awk to just set|egrep.      #
              #                                                                      #
              #----------------------------------------------------------------------#
            
Artificial Intelligence is no match for natural stupidity.
©Copyright Bob Orlando, 1998-2011
All rights reserved.
http://www.OrlandoKuntao.com
E-mail: Bob@OrlandoKuntao.com
Last update: Jan. 26, 2011
by Bob Orlando