> And in my opinion those are not correct...

So in a scenario like the mentioned
$ foo=bar; bar=moo; moo=123
the line
$ ((foo++)); echo $foo $bar $moo
should actually evaluate to
„bar moo 124“

or at least say something like
„error, can not execute side effects, because I 
can’t keep track of what I expanded in order to get a number"

which it does not…

I know that (()) probably was never intended for such a thing, but
it’d be a nice-to-have addition, while being certainly doable :)

> Am 23.04.2017 um 15:07 schrieb Florian Mayer <mayerflor...@me.com>:
> 
> It does not matter, how this construct in this particular context is called.
> The difference between $(()) and (()) is that $(()) actually expands to 
> something
> whereas (()) just executes a C-like expression. In ((<expression>)) 
> <expression> can also
> include assignments, as the bash manual that you properly cited, also 
> elaborates on.
> You can do, for example, things like
> $ foo=2
> $ ((foo+=100)) # fo is now 102
> $ ((++(foo++)))
> or even
> $ ((foo++, foo++, foo++, foo++, foo+=100))
> and (oh boy why) even
> $ foo=(123 321)
> $ ((foo[0]++, foo[1]—))
> 
> So I might have chosen the wrong subject text for this mail,
> but again, it does not matter whether those constructs actually expand to 
> some string
> or not. The side effects are what matter here. And in my opinion those are 
> not correct...
> 
>> Am 23.04.2017 um 14:43 schrieb Pierre Gaston <pierre.gas...@gmail.com 
>> <mailto:pierre.gas...@gmail.com>>:
>> 
>> 
>> 
>> On Sun, Apr 23, 2017 at 3:28 PM, Florian Mayer <mayerflor...@me.com 
>> <mailto:mayerflor...@me.com>> wrote:
>> What I’m saying is, that if bash does recursively apply expansion
>> mechanisms on the identifiers until it can retrieve a number, 
>> it should do it symmetrically. That is,
>> it should remember what chain of expansion had been necessary for
>> a particular number to appear at the end of the expansion.
>> 
>> So instead of 
>> 124 moo 123
>> The echo command should produce
>> bar moo 124
>> 
>> (The expansion chain here was foo->bar->moo->123)
>> 
>>> It's because it's not really indirection, rather the content of the 
>>> variable is evaluated:
>> No it is really indirection. Bash even has a special (and very limited) 
>> syntax for that.
>> Consider 
>> $ foo=bar; bar=moo
>> You can get the string „moo“ through foo by using
>> $ echo ${!foo}
>> 
>> $ echo ${!!foo} # or something else does not work, though...
>> 
>>  
>> This is indirection indeed, but in arithmetic evaluation it's not.
>> 
>> Quoting the manual:
>> 
>> "The value of a variable is evaluated as an  arithmetic  expression
>>  when  it  is  referenced, or when a variable which has been given the 
>> integer attribute using declare -i is assigned a value. "
>> 
>> Consider this:
>> foo=1+3
>> echo $foo
>> echo $((foo++))
>> echo $foo
>> 
> 

Reply via email to