A quick one...
Code:
$ echo "4:30" | grep '^[0-9][1-2]\{0,1\}:[0-5][0-9]'
4:30
Code:
#!/bin/bash
# Check if argument is a correct time
if [[ $(echo $1 | grep '^[0-9][1-2]\{0,1\}:[0-5][0-9]') ]]; then
echo "Correct time"
exit 0
else
echo "Invalid time"
exit 1
fi
On execution:
Code:
$ ./check_time.sh 9:12
Correct time
Code:
$ ./check_time.sh 4:71
Invalid time
Code:
$ ./check_time.sh 12:15
Correct time
This is a very simple regex that can be improved a lot. But since you are apparently dealing with am/pm times, and not a 24 hour clock, it is at least a start.
Best regards,
HMW