[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strange bug in arithmetic function
From: |
Davide Brini |
Subject: |
Re: Strange bug in arithmetic function |
Date: |
Tue, 22 Feb 2011 13:41:49 +0000 |
User-agent: |
KMail/1.13.5 (Linux/2.6.36-gentoo-r5; KDE/4.4.5; x86_64; ; ) |
On Monday 21 Feb 2011 09:13:54 Marcel de Reuver wrote:
> In a bash script I use: $[`date --date='this week' +'%V'`%2] to see if
> the week number is even.
> Only in week 08 the error is: bash: 08: value too great for base
> (error token is "08") the same in week 09, all others are Ok...
It's not a bug. First, you shouldn't use the ancient and deprecated $[ .. ]
syntax for arithmetic evaluation; use $(( .. )).
Second, bash interprets numbers with leading zeros as octal, thus "08" isn't a
valid octal number. You can force it to be interpreted as decimal by
prepending the base, eg see
$ echo $(( 08 + 2 ))
-su: 08: value too great for base (error token is "08")
$ echo $(( 10#08 + 2 ))
10
--
D.