From: Ron via Talk <talk@lists.gtalug.org>
But it's highly counter-intuitive (*who* here knew about this behaviour before this thread?).
And bash is littered with such weirdness.
Two values summing to zero gives the same result as "a" + "b"?!?
$ (("b"+"a")) ; echo $? 1
$ ( ((0+0)); echo $? ) 1
$ ( ((0+1)); echo $? ) 0
It's just mindbogglingly illogical and utterly nonsensical (in my not so humble opinion).
You seem to be reallly upset about what (( )) does for a result code. But it is clearly spelled out on the tin. What I'm upset about is that the ((,,,)) composite command is a hacky extension to the Bourne Shell. I have no idea why it is a good idea. I've never used it even though I've used the BASH since it was released. Allowing assignments within that expression that affect the environment outside is, uh, unnatural. But without them, the only purpose could be to set the result code. It does two things badly. A more natural form would be that (( )) evaluates an expression and produces a string that is the result. In addition, it sets the result code to reflect actual errors (eg. division by 0). The set -e would behave well. And while I'm complaining: why does (( )) allow for silent overflow when the result doesn't fit in some "fixed width integers"? At a minimum, it should fail on overflow. But in a language like this, it should just get the right answer, as a string. Things get dicier with fractions but they are not supported anyway. Oh, and that wording is silly because every integer has a fixed width; what they mean is that all calculations are done in some C integral type with undisclosed range. Yuck! Just a badly designed feature that trapped you. Don't use it unless you understand it.