You are not logged in.
The error is:
/home/scripts/others/polysleep: line 15: 60 - ((((((08: value too great for base (error
token is "08")
Here's the script (it's an alarm for naps of different lengths) :
#!/bin/bash
if [ $UID != "0" ]; then
echo "You must run this script as root." 1>&2
exit
fi
TIME_SET=`date +%M`
DELAY=60
while [ "1" -lt "2" ]
do
DATE=`date +%k:%M:%S`
MINUTE=`date +%M`
// The offending line:
REMAINING=$(($DELAY - (((((($MINUTE + 60)) - $TIME_SET)) % 60))))
// I want it to show how long is left before the time is up (ie. it subtracts the time that has
// passed from the $DELAY that was set). Since it's in minutes, I need to do the arithmetic
// in modulo 60 (the '% 60' bit) - I tried this initially without the '+ 60' above, but got the
// same error as I've posted, and thought that initially plus-ing 60 to $MINUTE (the
// minute section of 'date' at the current time) would solve it. Apparently that hasn't
// worked though =o(
clear
echo "1. I'm awake"
echo "2. I'm going for a nap"
echo "3. I'm going out"
echo
echo Current Time: $DATE
echo Time Remaining: $REMAINING minutes
read -t 1 -e input
if [ "$REMAINING" = "0" ]
then
play -v .15 /home/.sounds/alarm.mp3&
wait
DELAY=1
TIME_SET=`date +%M`
input=""
fi
if [ "$input" = "1" ]
then
DELAY=60
TIME_SET=`date +%M`
input=""
elif [ "$input" = "2" ]
then
DELAY=35
TIME_SET=`date +%M`
die centericq
input=""
elif [ "$input" = "3" ]
then
DELAY=999999
TIME_SET=`date +%M`
input=""
fi
done
I'd be grateful for advice, since apart from that error popping up after some time has passed, the script runs flawlessly.
.oO Komodo Dave Oo.
Offline
C'mon guys, I know there are some decent bash scripters out there...
.oO Komodo Dave Oo.
Offline
Every number that starts with zero is handled as octal value by bash and your $MINUTE and $TIME_SET get the leading 0's if they are < 10 because of the date output. Since there's no number 8 in octal bash is complaining that the value's too great for this base.
Either you need to get rid of the leading zeros or you tell bash to use base 10 (decimal) for these variables:
REMAINING=$(( $DELAY - (( 10#$MINUTE + 60 ) - 10#$TIME_SET ) % 60 ))
Btw. what were all these paranthesis in your code good for? :shock:
Offline
Thanks a lot for that info smoon, you're a lifesaver
Btw. what were all these paranthesis in your code good for? :shock:
This is from http://www.codecoffee.com/tipsforlinux/ … 2/044.html , and explains it better than I could:
"bash allows you to perform arithmetic expressions. As you have already seen, arithmetic is performed using the expr command. However, this, like the true command, is considered to be slow. The reason is that in order to run true and expr, the shell has to start them up. A better way is to use a built in shell feature which is quicker. So an alternative to true, as we have also seen, is the ":" command. An alternative to using expr, is to enclose the arithmetic operation inside $((...)). This is different from $(...)."
.oO Komodo Dave Oo.
Offline
(...)
This is from http://www.codecoffee.com/tipsforlinux/ … 2/044.html , and explains it better than I could:"bash allows you to perform arithmetic expressions. As you have already seen, arithmetic is performed using the expr command. However, this, like the true command, is considered to be slow. The reason is that in order to run true and expr, the shell has to start them up. A better way is to use a built in shell feature which is quicker. So an alternative to true, as we have also seen, is the ":" command. An alternative to using expr, is to enclose the arithmetic operation inside $((...)). This is different from $(...)."
Yeah, I knew that already. But what I meant were the extra paranthesis you're using. This is the calculation the way you do it:
REMAINING=$(($DELAY - (((((($MINUTE + 60)) - $TIME_SET)) % 60))))
But this is totally adequate:
REMAINING=$(( $DELAY - (( $MINUTE + 60 ) - $TIME_SET ) % 60 ))
Notice the 6 vs. 2 brackets in front of $MINUTE?
Offline
Sorry smoon, I was in a rush and didn't look at your code properly - it's because I was doing it at 4am last night, and I'm adjusting to polyphasic sleep atm, meaning I get <2 hours of sleep every 24 hours. So as you can imagine, I'm pretty messed up right now, lol
.oO Komodo Dave Oo.
Offline