If condition not working

Hi Gurus,

I have shell script in which i have to check if time is between to possible value or not. For that i am using following line of code

if [ "$ftime" -gt 01:00 && "$ftime" -lt 05:00 ]
then
echo 'Found In Between'
echo $ftime
fi
but when i am executing the script i am getting
test: ] missing
error.

Please help me to resolve this.

Thanks in Advance
Manish

if [ "$ftime" -gt 01:00 -a "$ftime" -lt 05:00 ]
then
echo 'Found In Between'
echo $ftime
fi

You can use -a instead of &&

mmm...
I think -gt, -lt, etc... are for integers and not for dates. At least in my AIX, where "man test" shows:

[...]
Integer1 -eq Integer2 Returns a True exit value if the Integer1 and Integer2
variables are algebraically equal. Any of the comparisons -ne, -gt, -ge, -lt,
and -le can be used in place of -eq.
[...]

manish if u wish u can try with this

cut minutes and hours in two variables

hr=`time | cut -c 1-2`
mn=`date | cut -c 3-4`

then compare separately according to ur requirement
if [ hr -gt ?? -a hr -lt ?? ]

Or (my pref) use ...

hr=`date +'%H'` (24hr format) //or// hr=`date +'%I'` (12hr format)
mn=`date +'%M'`

Hope the following will help you.

if [[ "$ftime" > "01:00"&&"$ftime" < "05:00" ]]; then
echo "$ftime"
fi