How to Validate

I have one script by which I am taking Extraction Schedule in the following format [HH:MM],[HH:MM],[HH:MM],......[HH:MM]

Here I want validate the Input from user is okey or not.
Let say i have one variable SCH
SCH=12:34,23:12,11:20

Could you please tell me how I will validate it.
HH & MM Both should be Numeric
HH should not Greater then 24
MM should not greater then 60
Note: Here I am using comma (,) as a delimeter.

Thanks
Sanjay

Could anyone let me know if
SCH=12:34,23:12,11:20... N numbers
How can I print like below
12:34
23:12
11:20

echo ${SCH} | tr ',' '\n'

Bingo !!!

Thanks Vino Bro !!

Anyone who can help me !!!

I have one script by which I am taking Extraction Schedule in the following format [HH:MM],[HH:MM],[HH:MM],......[HH:MM]

Here I want validate the Input from user is okey or not.
Let say i have one variable SCH
SCH=12:34,23:12,11:20

Could you please tell me how I will validate it.
HH & MM Both should be Numeric
HH should not Greater then 24
MM should not greater then 60
Note: Here I am using comma (,) as a delimeter.

Thanks
Sanjay

Myscript is test.sh is looks like
_________________________________
#!/bin/bash
echo -n "Enter Time schedule in the following format [HH:MM],[HH:MM],..:"
read Ext_Sch
for val in `echo $Ext_Sch |tr ',' '\n'`
do
tmp=""
tmp=`echo $val | grep "^[0-2][0-4]:[0-6][0-9]"`
echo " After getting the Value of tmp is $tmp"
if [ "$tmp" = "" ]
then
echo "Invalid Format !! Re-enter Time schedule in the following format [HH:MM],[HH:MM],..:"
continue
fi
break
done
-------------------
I want give input like 27:40,10:30,17:40

Here this scripts should validate the HH:MM !!!
Please help me out :frowning:

if you have GNU date, it might be easier to do this method of checking

# date -d "18:99"
date: invalid date `18:99'
# echo $?
1
# date -d "18:59"
Wed Sep 26 18:59:00 
# echo $?
0

Ghost Thanks for your quick response !!
Now I am using that date with in my script
-------------
echo -n "Enter Time schedule in the following format [HH:MM],[HH:MM],..:"
read Ext_Sch
date -d $Ext_Sch
count=`echo $?`
if [ $count -eq 0 ]
then
echo Valid
else
echo Wrong
fi
------------
[Sanjaytmp]$ sh tt.sh
Enter Time schedule in the following format [HH:MM],[HH:MM],..:28:33
date: invalid date `28:33'
Wrong
---------------------
[Sanjaytmp]$Enter Time schedule in the following format [HH:MM],[HH:MM],..:23:45
Thu Sep 27 23:45:00 IST 2007
Valid

Here I am getting the message in my output(show in bold letter) as well that I dun want.
Could you help me how I will ignore it.

Thanks
Sanjay

Perhaps something like this.

[/tmp]$ cat try.ksh
#! /bin/ksh

str=a:23,23:12,11:20,25:67

echo $str | tr ',' '\n' | while IFS=: read hour min
do
    if [[ $hour = *[:alpha:]* ]] ; then
        echo "$hour:$min is invalid"
    elif [[ $hour -lt 0 || $hour -gt 23 || $min -lt 0 || $min -gt 60 ]] ; then
        echo "$hour:$min is wrong"
    else
        echo $hour:$min
    fi;
done
[/tmp]$ ./try.ksh
a:23 is invalid
23:12
11:20
25:67 is wrong
[/tmp]$ 
# date -d "18:99" > /dev/null 2>&1
# echo $?
1

Bingo !!!! :slight_smile:

Ghost It wokring for me perfect ...
Thanks a lot !!