time arithmetic

Can anyone help please. I am writing a kourne shell script and I am unsure how to do the following:

I have extracted a time string from a logfile, and I have another time string I want to compare it to to see if it's later than the time I'm comparing with.

i.e. expectedSLA="23:00:00", actualDeliveryTime="22:40:00"

I try to do the following:

missedSLA="N"
if [ $actualDeliveryTime > $expectedSLA ]
then
missedSLA="Y"
fi

This always sets missedSLA to "Y". Isn't it supposed to compare using the decimal values of the string? How can I get the above process to work? What can I do? Any help would be greatly appreciated.

Many thanks,

Looking at your code I couldn't believe that it would run at all. But I tried "echo aaa > bbb ccc" and sure enough I created a file called bbb with the contents "aaa ccc". I never knew you could inbed redirects in the middle of an argument list.

That's what you are doing with "if [ $a > $b ]". You should be creating an output file. The [ is just a normal unix command that expects it's last argument to be ]. In the early days of the bourne shell, it was a link to the test command and sat in /usr/bin. Later it became a built-in, but it still is a command. It never understood > as a comparison operator. There is a -gt but it only works on integers and will barf on your time format.

You don't want an integer compare, you want an ascii string compare. So switch to [[ which is a keyword rather than a command:
if [[ $a > $b ]]
should work fine.

And it's korn, not korne. :slight_smile:

thanks that works just fine.

cheers mate.