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

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.


As others have said, the error results from Bash interpreting digit sequences with leading zeros as octal numbers. If you have control over the process creating the date values and you're using date, you can prefix the output format string with a hyphen to remove leading zero padding.

Without prefixing date format with hyphen:

$ (( $(date --date='9:00' +%H) > 10 )) && echo true || echo oops
-bash: ((: 09: value too great for base (error token is "09")
oops

With prefixing date format with hyphen:

$ (( $(date --date='9:00' +%H) > 10 )) && echo true || echo oops
true

From the date man page:

By default, date pads numeric fields with zeroes. The following optional flags may follow '%':

  -      (hyphen) do not pad the field

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

Tags:

Bash