On Sun, Apr 23, 2017 at 4:07 PM, Florian Mayer <mayerflor...@me.com> wrote:

> 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...
>

I understand what you want, I'm just explaining the result you get
and why it doesn't do what you want.
As it is, a variable can contain the name of another variable
but it can also contain any arbitrary string that is a correct arithmetic
expression.

So if you have:

foo=bar+14+baz
baz='moo*2'
moo=1

what shoud echo $((foo++)) do?

Your case is only really a special case, arguably having only indirection
instead of what we have
would perhaps have been a better idea, but it is this way for so long that
I doubt it will change.

PS: you can perhaps use name reference instead
moo=1;
declare -n foo=bar bar=moo
echo $((foo++))
echo $moo

Reply via email to