Calculating delay time - bash

Hi,

I am having the following problem.

test > hourOfDay=06 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
180
test > hourOfDay=07 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
120
test > hourOfDay=08 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
bash: (9-08: value too great for base (error token is "08")
test > hourOfDay=09 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
bash: (9-09: value too great for base (error token is "09")
test > hourOfDay=10 ; delayTime=$(((9-$hourOfDay)*60)) ; echo $delayTime
-60

you can see where hourOfDay = 08 or 09 I get the error
bash: (9-08: value too great for base (error token is "08")

does it think that these are base 8 numbers ?
because of the leading "0" ?

In my script I get the hourOfDay using
hourOfDay=$(date +%H)

Is there an easy way to strip off the '0', if that is the problem ?
(sorry if this is an easy thing, I mess with scripts less than once a month,
so not very experienced).

Thanks !
joe

the leading zero is indeed the problem.

too bad it's not past 1:00pm here.... otherwise i could help. :slight_smile:

but you might try something like:

### Tue Apr 14 11:24:18 EDT 2009
set `date | sed -e 's/:confused: /g'`
hours=$4

I think that doesn't have leading zeroes... More after 1:00 if solution isn't posted by then.

Thanks. I will try it ...

FYI - for testing purposes you could use hourOfDay=$(date +%m), to get the month "04".

Thanks !
joe

thanks

date +%m | sed -e 's/0//g'

Seems to do the right thing

not quite.
it'll mangle 10:00 o'clock.

Try:

date +%H | sed -e 's/^0//'

need that caret.

wooo whooo , thanks !