#!/usr/bin/ksh93 ################################################################ function usagemsg_evenodd_k93 { print " Program: evenodd_k93 The evenodd_k93 Korn Shell command/function examines a number from the command line and returns a 0 or 1 to indicate even or odd. Optionally will return the word "even" or "odd" to standard output. Usage: ${1##*/} [-v] [-V] [-?] -n NUMBER Where: '-n NUMBER' = Number to examine for even or odd '-v' = Verbose mode, return word "even" or "odd" '-V' = Very Verbose Mode Author: Dana French (dfrench@mtxia.com) Copyright 2004 \"AutoContent\" enabled" return 0 } ################################################################ #### #### Description: #### #### Assumptions: #### #### Dependencies: #### #### Products: #### #### Configured Usage: #### #### Details: #### ################################################################ function evenodd_k93 { typeset TRUE="0" typeset FALSE="1" typeset VERBOSE="${FALSE}" typeset VERYVERB="${FALSE}" typeset NUMBER="" while getopts ":n#vV" OPTION do case "${OPTION}" in 'n') NUMBER="${OPTARG}";; 'v') VERBOSE="${TRUE}";; 'V') VERYVERB="${TRUE}";; '?') usagemsg_evenodd_k93 "${0}" && return 1;; ':') print -u 2 "ERROR: Invalid option argument, not a number" usagemsg_evenodd_k93 "${0}" return 1;; esac done shift $(( ${OPTIND} - 1 )) trap 'usagemsg_evenodd_k93 ${0}' EXIT [[ "_${NUMBER}" = "_" ]] && print -u 2 "ERROR: Number not specified" && exit -1 trap '-' EXIT (( VERYVERB == TRUE )) && set -x ################################################################ case ${NUMBER} in *[02468]) (( VERBOSE == TRUE )) && print "even" return 0;; *[13579]) (( VERBOSE == TRUE )) && print "odd" return 1;; *) (( VERBOSE == TRUE )) && print -u 2 "ERROR: Not a number" return -2;; esac return -3 } ################################################################ evenodd_k93 "${@}"