check for numbers

Hi,

I have a requirement to accet only numbers. Piece of code beolow.

waitTime() {
echo "Enter amount of time to wait (in sec)."
read wait_time
sleep $wait_time
}
the above function should accept only numbers otherwise, it has t throw an error.

Please help.

read_num(){
        echo "please enter a number"
        read num
        isNum=$(echo $num | awk -v num=$num '{if( num ~ /^[1-9][0-9]*$/ ) {print "0"} else {print "1"}}')
        if [[ $isNum -eq "0" ]]; then
                echo "sleep for $num seconds"
        else
                read_num
        fi
}

There's no need for an external command:

## USAGE: is_num NUM
## RESULT: in $?: 0 if NUM is a positive integer; 1 if not
is_num()
{
  case $1 in
    *[!0-9]*) return 1 ;;
  esac
}