Click to See Complete Forum and Search --> : errors with time?
TGrimace
08-28-2002, 11:27 AM
This seems like a very simple code that should work fine. And it does, except when the minute is 08 or 09, and I have no idea why or how to fix it. If the minute is 04 or 07 or 18 or 25 or anything except 08 and 09, it works very smoothly. Could someone tell me why?
#!/bin/sh
TRUE=1
while (TRUE=1)
do
{
NOW_MINUTE=`date +%M`
echo $NOW_MINUTE
let NEXT_MINUTE=1+$NOW_MINUTE
echo $NEXT_MINUTE
sleep 30
}
done
Rüpel
08-28-2002, 03:26 PM
your problem is octal ;)
the numbers are returned 01-09,10..59 and numbers beginning with "0" are interpreted as octal.
everything is fine up to 07. but 08 is simply a wrong token. you cant write a binary number as 0100112010 right? so in octal-format only digits from 0 to 7 are allowed.
try at your bash-prompt the following:
let next=010+03
do you think echo $next will be 13? wrong! the result is 11. because the octal number 010 is equal to the decimal 8.
so you should think of some way to get the minutes without the zero in front...
maybe something like this between the backquotes:
date +%M | sed s/08/8/ | sed s/09/9/
yes i know this could be done with one regex, but i can't remember everything now...still a noob :rolleyes:
TGrimace
08-28-2002, 03:31 PM
cool thanks. But I ended up just throwing a couple of if/then statement in there. Cleared it up pretty well.
NOW_MINUTE=`date +%M`
echo $NOW_MINUTE
if [ $NOW_MINUTE -eq 08 ]
then
let NOW_MINUTE=8
fi
if [ $NOW_MINUTE -eq 09 ]
then
let NOW_MINUTE=9
fi