Error : bash: 08: value too great for base (error token is “08”)

Error Message : bash: 08: value too great for base (error token is “08”)  or  bash: 09: value too great for base (error token is “09”)

This error message is seen when an arithmetic operation is performed on numbers which has value 08 or 09.  Mostly when dealing with months and days.

Reason : As the number start with 0, linux assumes it as number with Octal base and since there are no 8 and 9 in octal it throws the above error.

Solution : Convert the number 08 to 8, do the arithmetic operation and later convert it back if needed.

Example :

$ mm=08
#Converting  08 to 8
$ mm1=$(echo $mm| awk '{printf "%d\n",$0;}')
$ echo $mm1
# Adding 1 to 8
$mm1=$(($mm1+1))
$ echo $mm1
# Converting 9 to 09
$mm2=$(printf %02d $mm1)
$echo $mm2
09

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.