Hello All,

I am facing one basic problem please help me out

here is my script

while [ 1 ]
sleep 2

data=16:37

one=15:00
two=17:00


I need to check that is data lies between one and two ( data has to satisfy both one and two )

done

how?

please help ....!!!!!!

a simple if statment will work

this isnt the syntax but just a clue!

if data > one && data < two
then
do something
else
do something else
fi

You should note these forums arent for using us to do your homework if you show some effort we will help but we wont do it for u!

Another suggestion - since it looks like you are comparing military time, it will be easier to make the comparison if you drop the ":".

You can do this with sed or tr or even cut very easily.
After that, you can do the if comparison. Otherwise you will need to use cut to break each time into two integers for comparison with three logics!

Okay, I needed something to get my mind off work for a few minutes, so here's a quick script I wrote using both of the suggestions above from chris5126 and omrsafetyo. I didn't translate the date, I used the date command to format the date without colons. Here goes, hope it helps!

#!/bin/sh

one=143300
two=143400

while true; do

  time="$(date +%H%M%S)"

  if [ $time -gt $one ] && [ $time -lt $two ]; then
    echo "$time We're in the zone\!"

  elif [ $time -gt $one ] && [ $time -gt $two ]; then
    echo "$time The time has passed"

  elif [ $time -lt $one ] && [ $time -lt $two ]; then
    echo "$time It's not time yet..."
  fi

  sleep 10

done

And here's the output:

$ sh ./timecompare.sh 
143204 It's not time yet...
143214 It's not time yet...
143224 It's not time yet...
143234 It's not time yet...
143244 It's not time yet...
143254 It's not time yet...
143304 We're in the zone\!
143314 We're in the zone\!
143324 We're in the zone\!
143334 We're in the zone\!
143344 We're in the zone\!
143354 We're in the zone\!
143404 The time has passed
143414 The time has passed

Enjoy!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.