Value too great for base (error token is "09")

When running this part of my bash script am getting an error

Script

value=0
for (( t=0; t <= 4; t++ ))
do
d1=${filedates[$t]}
d2=${filedates[$t+1]}
((diff_sec=d2-d1))
SEC=$diff_sec
compare=$((${SEC}/(60*60*24)))
value=$((value+compare))
done

Output

jad.sh: line 28: ((: 10#2014-01-09: value too great for base (error token is "09")
jad.sh: line 30: /(60*60*24): syntax error: operand expected (error token is "/(60*60*24)")

d1 and d2 are dates in that form 2014-01-09 and 2014-01-10

Any solution please?


Prepend the string "10#" to the front of your variables. That forces bash to treat them as decimal, even though the leading zero would normally make them octal.


What are d1 and d2? Are they dates or seconds?

Generally, this error occurs if you are trying to do arithmetic with numbers containing a zero-prefix e.g. 09.

Example:

$ echo $((09+1))
-bash: 09: value too great for base (error token is "09")

In order to perform arithmetic with 0-prefixed numbers you need to tell bash to use base-10 by specifying 10#:

$ echo $((10#09+1))
10