| | |
How to check my conditions....!!!
![]() |
•
•
Join Date: Feb 2006
Posts: 399
Reputation:
Solved Threads: 14
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!
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!
If my post helped add to my rep!
•
•
Join Date: Apr 2008
Posts: 58
Reputation:
Solved Threads: 9
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!
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!
And here's the output:
Enjoy!
Shell Scripting Syntax (Toggle Plain Text)
#!/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:
Shell Scripting Syntax (Toggle Plain Text)
$ 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!
![]() |
Similar Threads
- C / C++ FAQ's and Practice problems (C++)
- Logical operations and data-checks (Java)
- Big Problem , cannot fix it (Java)
- simplified bubble sort c++ (C++)
- How to give 2 Conditions in an SQL Query (VB.NET)
- image manipulation (C#)
- PLEASE!! Assignment Hollow rectangle with (*) (C++)
- Please point me in the right way for the ending of my C program. (C)
- how do i set the conditions in this case? (C#)
Other Threads in the Shell Scripting Forum
- Previous Thread: awk percentage problem
- Next Thread: How to generate a temp file until finish selected then replace to another file.
| Thread Tools | Search this Thread |





