Glam Prestige Journal

Bright entertainment trends with youth appeal.

So, I'm trying to calculate 12-08 (not 12-8) and get the following error:

let: 08: value too great for base (error token is "08")

Here's the sample code:

first=12
second=08
if [[ ($first > $second) ]]; then let fin=first-second
else let fin=second-first
fi

P.S Sorry about the spacings

1

1 Answer

If you precede a number by 0, bash treats the number as octal. As octal is base 8 with digits ranging from 0 to 7, 08 is out of range for octal.

Now you have two options to do decimal calculation:

  • Omit preceding 0:

    $ echo $(( 12 - 8 ))
    4
  • Explicitly mention base as decimal by 10#:

    $ echo $(( 12 - 10#08 ))
    4
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy