# SccsId[] = "%W% (USL function) %G%"
              VNV_name="VERIFY_NUM_VARS"
              if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
                 [ ."`set|egrep '^$VNV_name\(\)\{$'`" != . ] && VNV_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 '/^'$VNV_name'[=\(]?/'`" != . ] && VNV_loaded=1
                 else # Linux
                    [ ."`typeset -F|awk '/^'$VNV_name'[=\(]?/'`" != . ] && VNV_loaded=1
                 fi
              fi
              if [ 0${VNV_loaded} -eq 0 ]; then
              #----------------------------------------------------------------------#
              VERIFY_NUM_VARS() # 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 the following variables are not set, use these defaults.#
                #------------------------------------------------------------#
                : ${script_name:=`basename $0`}
                : ${sp:="                    "}

                VNV_ID="$script_name($VNV_name)"

                if [ $# -gt 0 ]; then
                   #-----------------------------------------------------------------#
                   # The trick here is to run the entire block of code in background #
                   # (hence the beginning and end parentheses on separate lines).    #
                   # Doing this allows us to use environmental variables (the only   #
                   # ones nawk is capable of seeing) without affecting any that have #
                   # identical names in foreground which might have the same names.  #
                   # (Wow is this ever faster than the way I did it before!)         #
                   #                                                                 #
                   VNV_errors=`( # Begin background operation.
                      export $*  # Export these dogs so nawk can examine them.
                    #--------------------------------------------------------------#
                    # FYI: If you want to sort the variables and eliminate dupes   #
                    #      you can do the following:                               #
                    # echo $*|awk "{for (n=1;n<=NF;n++) print $n}"| sort | uniq \  #
                    #  | $AWK "BEGIN { p = q = 0 } ... (ommitting the RS = "").    #
                    #--------------------------------------------------------------#
                      echo $* | $AWK -v sp="$sp" \
                       'BEGIN { RS = " "; p = q = 0 } # Initialization

                        #----------------------------------------------#
                        # Action section runs through our variables    #
                        # and assigns them to our var[] array.         #
                        #----------------------------------------------#
                        { var[++q] = $1 }

                        #----------------------------------------------#
                        # This is where we verify variable assignments.#
                        #----------------------------------------------#
                        END \
                        { err_n = 0
                          for (p=1; p<=q; p++)
                          {
                            gsub(/[\n\r\t ]+/,"",ENVIRON[var[p]])
                            if (ENVIRON[var[p]] == "")
                            {
                              print sp"$"var[p]" is unassigned."
                              err_n++
                            }
                            else if (ENVIRON[var[p]] !~ /^[\-\+]*[0-9]+\.*[0-9]*$/)
                            {
                              print sp"NOT numeric $"var[p]"\t("ENVIRON[var[p]]")."
                              err_n++
                            }
                          }
                          exit err_n
                        }'
                   ) 2>&1` # End of background export and nawk process.
                   [ $? -eq 0 ] && return 0
                 #                                                                 #
                 #-----------------------------------------------------------------#
                fi

                #--------------------------------------------------------------#
                # Reaching this point means that we either have insufficient   #
                # args or the nawk process uncovered an unassigned or invalid  #
                # variable.                                                    #
                #--------------------------------------------------------------#
                if [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi

                . $SHLIB/exit.sh                 # Function dependencies
                . $SHLIB/email_msg.sh            # Calls $SHLIB/exit.sh
                . $SHLIB/write_err_to_syslogs.sh

                VNV_msg="$script_name terminated."
                if [ $# -lt 1 ]; then
                   VNV_errors="Insufficient args!"
                   EMAIL_MSG "FATAL ERROR (Function): $VNV_ID"               \
                     "${sp}$VNV_errors"                                      \
                     "${sp}Usage: $VNV_name var ...\n"                       \
                     "${sp}Usually a list, 'num_var' is a critical variable" \
                     "${sp}name that we check to ensure that it is both"     \
                     "${sp}assigned and that it is assigned a numeric value" \
                     "${sp}(positive or negative integers or floats).\n"     \
                     "${sp}       NOTE: 'var' MUST NOT have leading '$'."    \
                     "\n${sp}$VNV_msg"
                else
                   EMAIL_MSG "FATAL ERROR: $VNV_ID" \
                     "${sp}$VNV_errors"             \
                     "${sp}$VNV_msg"
                fi

                if [ ."${TERM}" = . ]; then
                   WRITE_ERR_TO_SYSLOGS $syslog_emergency \
                     "ABORT: $VNV_ID $VNV_errors $VNV_msg"
                fi

                EXIT 1
              } # "VNV_" prefix identifies this function's variables
              fi

              #======================================================================#
              #                       D O C U M E N T A T I O N                      #
              #======================================================================#
              #                                                                      #
              #      Author: Bob Orlando                                             #
              #                                                                      #
              #        Date: March 13, 1998                                          #
              #                                                                      #
              #  Program ID: verify_num_vars.sh                                      #
              #                                                                      #
              #       Usage: VERIFY_NUM_VARS num_var ...                             #
              #                                                                      #
              #                 Usually a list, 'num_var' is a critical variable     #
              #                 name that we check to ensure that it is both         #
              #                 assigned and that it is assigned a numeric value     #
              #                 (positive or negative integers or floats).           #
              #                                                                      #
              #     Purpose: Verify the assignment of critical numeric process       #
              #              variables. Because they are critical to the operation   #
              #              of the process, finding any unassigned (or assigned     #
              #              a non-integer value) terminates the process.  (ALL      #
              #              the unassigned variables are reported at that time.)    #
              #                                                                      #
              #     Globals: No global variables are assigned in this function.      #
              #              "VNV_" prefix identifies local function variables.      #
              #                                                                      #
              # Exit_status: Exits with 1 (failure) for severe error (e.g. user      #
              #              supplies an invalid argument) or if any of the          #
              #              variables are unassigned or not numeric.  Otherwise,    #
              #              returns 0 (success).                                    #
              #                                                                      #
              #       Calls: EMAIL_MSG and WRITE_ERR_TO_SYSLOGS library functions.   #
              #                                                                      #
              #       Notes: ....................................................    #
              #              ....................................................    #
              #                                                                      #
              #    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