the user have to input the date format in mmddmmhhyyyy (month,date,minutes,hour,year)
i want a shell script to check whether the user has properly input in the above said manner.
kindly advice
read date
if [ ${#date} -lt 12 ]
then
echo Not enough information
elif [ ${#date} -gt 12 ]
then
echo Too much information
else
case $date in
*[!0-9]*) echo Invalid character entered ;;
*) echo Thank you ;;
esac
fi
Then you should check that the values for each component are within a valid range.
If have GNU date you can use date to check it, but the input must be in an accepted format of date (see: man date), maybe you can ask the user to input the date directly in the good format. It will check if it's really a valid date.
until date -d $DATE
do read -p "Enter date: " DATE
done