bash "let" barfs on addition

Daevid Vincent daevid at daevid.com
Thu Mar 12 19:12:43 UTC 2009


Well, whenever I see a negative number, my first inclination is you've
got a SIGNED INTEGER (vs. UNSIGNED) and so you hit MAXINT and flipped.

http://en.wikipedia.org/wiki/Signedness

-----Original Message-----
From: Evuraan::ഏവൂരാന്‍ <evuraan at gmail.com>
Reply-to: "Ubuntu user technical support, not for general discussions"
<ubuntu-users at lists.ubuntu.com>
To: Ubuntu user technical support, not for general discussions
<ubuntu-users at lists.ubuntu.com>
Subject: bash "let" barfs on addition
Date: Thu, 12 Mar 2009 11:57:12 -0700


Greetings y'all..!

Seen this sort of behaviour before? :

mybash:>  a="7540113804746346429"
mybash:>  b="4660046610375530309"
mybash:> let c=(a+b)
mybash:> echo $c
-6246583658587674878

The correct answer should have been: 12200160415121876738

mybash:> echo "$a+$b" |bc -l
12200160415121876738


mybash:> bash --version
GNU bash, version 3.2.25(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
mybash:>

I know, I can use bc,dc,awk, python and even a desk calculator  wide
enough :) - but, I am curious as to why is "let" letting us down?

Does a known bug exist already?

Any input would be much appreciated, many thanks in advance.!



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20090312/6728c229/attachment.html>


More information about the ubuntu-users mailing list