erratic sh arithmetic
Karl Auer
kauer at biplane.com.au
Fri Jul 10 04:19:37 UTC 2020
On Thu, 2020-07-09 at 21:21 -0600, Gary Aitken wrote:
> I'm seeing crazy erratic behavior in sh arithmetic executing in
> a cron script as root:
Haven't looked closely, but any value beginning with "0" is regarded as
octal, so 08 (also 09, 18, 19, 28 and 29) should be throwing "value too
great for base".
week=$(( ( 8 + 6 - 3 ) / 7 + 1 ))
works for me, but
week=$(( ( 08 + 6 - 3 ) / 7 + 1 ))
Results in:
bash: ( 08: value too great for base (error token is "08")
If it's been up for two weeks, running daily, you should have had a
similar error on 28 and 29 June.
BTW,
week=`expr \( 08 + 6 - 3 \) / 7 + 1`
works for me too, which I have to say was a bit of a surprise, I
expected expr to understand octal, and my doco for expr says it does
too. But this returns 3; if it understood octal it would return 2:
week=`expr \( "011" + 6 - 3 \) / 7 + 1`
Regards, K.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer
http://twitter.com/kauer389
GPG fingerprint: 2561 E9EC D868 E73C 8AF1 49CF EE50 4B1D CCA1 5170
Old fingerprint: 8D08 9CAA 649A AFEF E862 062A 2E97 42D4 A2A0 616D
More information about the ubuntu-users
mailing list