Datecheck command (date comparison)
Hey,
I've written a command that allows you to take different actions based on the day. Would anybody else find it useful? Here are some of my tests from yesterday:
grub> if [ datecheck -gt 2009-3-20 = datecheck -lt 2009-06-21 ]; then echo; ech
o "It is spring!"; fi
It is spring!
error: unrecognized number
grub> if datecheck -gt 15; then echo "It is after the 15th of the month."; fi It is after the 15th of the month.
grub> if datecheck -lt -w 2; then echo "It is before Tuesday."; fi grub> if datecheck -eq -w 2; then echo "It is Tuesday."; fi
It is Tuesday.
grub> if datecheck 19; then echo "It is the 19th."; fi
It is the 19th.
grub> if datecheck -gt 05-10; then echo "It is after May 10th."; fi It is after May 10th.
grub> if datecheck -w 0; then echo "It is Sunday."; fi
grub>
You might notice that there are two bugs associated with the first test. It was an attempt to test two conditions at once, and without being able to find any documentation (or anybody willing to answer scripting questions), that is what I came up with. The "error:
unrecognized number" part may be due to this.
Because the command spanned two lines, an extra "echo" had to be added so that the full command could be seen clearly. Without that, the words would have overwritten the wrapped portion of the command.
The command is written in a lax manner that attempts to interpret whatever it is given. You can do nonsensical things such as check if today is before the 20th day of the week. It may be worth printing an error message for that but I didn't think it necessary.
If anybody is interested, I have a patch for the SVN from a few days ago (before the segfault on grub-install). Some of the changes since then prevent it from being fully applied but the modifications required would be minor.
Signature · 1 line
Chris Umphress <http://www.epicvoyage.org>
Am Mittwoch, den 20.05.2009, 09:43 -0500 schrieb Chris Umphress:
Quoted 3 lines
I've written a command that allows you to take different actions based on the day. Would anybody else find it useful? Here are some of my tests from yesterday:
Hello,
can't this just be done with the variables Bean introduced with his datehook stuff[0]? $YEAR, $MONTH, $DAY, $HOUR, $MINUTE, $SECOND and $WEEKDAY.
Though I never used this myself.
[0] http://lists.gnu.org/archive/html/grub-devel/2008-08/msg00274.html
Signature · 1 line
Felix Zielcke
Quoted 6 lines · Felix Zielcke
can't this just be done with the variables Bean introduced with his datehook stuff[0]? $YEAR, $MONTH, $DAY, $HOUR, $MINUTE, $SECOND and $WEEKDAY.
Though I never used this myself.[0] http://lists.gnu.org/archive/html/grub-devel/2008-08/msg00274.html
Hmm, it would have been nice to know about this before. I haven't succeeded in getting these variables to work so far today though. The "set" command doesn't reflect that they exist, "echo $WEEKDAY" just shows a blank line, and an if statement utilizing the variables always returns "error: false"
Am I missing something?
Signature · 1 line
Chris Umphress <http://www.epicvoyage.org>
Hi,
Have you forgotten "insmod datehook" ?
Quoted 25 lines · Chris Umphress
Quoted 6 lines · Felix Zielcke
can't this just be done with the variables Bean introduced with his datehook stuff[0]? $YEAR, $MONTH, $DAY, $HOUR, $MINUTE, $SECOND and $WEEKDAY.
Though I never used this myself.[0] http://lists.gnu.org/archive/html/grub-devel/2008-08/msg00274.html
Hmm, it would have been nice to know about this before. I haven't succeeded in getting these variables to work so far today though. The "set" command doesn't reflect that they exist, "echo $WEEKDAY" just shows a blank line, and an if statement utilizing the variables always returns "error: false"
Am I missing something?
--
Chris Umphress <http://www.epicvoyage.org>_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
Quoted 3 lines · Bean
Hi,
Have you forgotten "insmod datehook" ?
It looks like I was. Thanks!
Signature · 1 line
Chris Umphress <http://www.epicvoyage.org>