Alain D D Williams wrote in
<20221229173548.GW16276@phcomp.co.uk>:
|On Thu, Dec 29, 2022 at 06:23:09PM +0100, Steffen Nurpmeso wrote:
|> Hello.
|>
|> Name: bash
|> Path: /usr/ports/core
|> Version: 5.2.15
|> Release: 1
|>
|> $ i=10 j=20;echo $(( i += j += i += j ));echo $i,$j
|> 60
|> 60,50
|> $ i=10 j=20;echo $(( i += j += i += i ));echo $i,$j
|> 50
|> 50,40
|
|You are modifying something that is used elsewhere in an expression. \
|I am not
|surprised that you do not get what you expect; others might expect \
|something
|different.
|
|At most there should be a note in the documentation that this sort of thing
|leads to undefined behaviour -- that is what happens in other languages.
|
|This is very much not a bug in bash.
I very much disagree. My mailer's $(()) evaluator also does this
right. (And busybox's one, if it gets accepted.)
|C does it differently. I would not be surprised to see different C \
|compilers
|produce different results or different results with different levels of
|optimisation.
Come on. Be a brave man.
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)