bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Curious case of arithmetic expansion


From: Florian Mayer
Subject: Re: Curious case of arithmetic expansion
Date: Sun, 23 Apr 2017 14:28:01 +0200

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



It prints "124 moo 123" no?

It's because it's not really indirection, rather the content of the variable is evaluated:

$ foo=1+2;echo $((foo))
3

In the last case it evaluates the value of foo, 123, and then increment the value of foo and foo becomes 124



reply via email to

[Prev in Thread] Current Thread [Next in Thread]