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.
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
}