Hello,
I need to take the input from user on below format and validate it.
ddd:hr:mm where ddd=mon-sun(days) , hr:hour (0-23) , mm=min(0-59).
Please assist me for getting input from user.
Thanks
Qamar
Hello,
I need to take the input from user on below format and validate it.
ddd:hr:mm where ddd=mon-sun(days) , hr:hour (0-23) , mm=min(0-59).
Please assist me for getting input from user.
Thanks
Qamar
OLDIFS="$IFS"
IFS=":"
while true
do
printf "Enter time: "
read DDD HH MM
case "$DDD" in
sun|mon|tue|wed|thu|fri|sat|sun) ;;
*) continue ;;
esac
case "$MM" in
[0-5][0-9]) ;;
*) continue;;
esac
case "$HH" in
[0-1][0-9]) ;;
2[0-3]) ;;
*) continue;;
esac
break
done
IFS="$OLDIFS"
Nice solution corona688.
@qamar.alam, you can also print error/help messages before calling continue eg:
*) echo "Hour must be between 0 and 23 - please reenter" ; continue ;;
Thank you so much corona688... It's really good and straight forward solution.