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: Pierre Gaston
Subject: Re: Curious case of arithmetic expansion
Date: Sun, 23 Apr 2017 14:55:28 +0300



On Sun, Apr 23, 2017 at 1:12 PM, Florian Mayer <address@hidden> wrote:
Consider

$ foo=bar; bar=moo; moo=123
$ echo $foo $bar $moo
=> bar moo 123
$ echo $((foo))
=> 123
$ echo $foo $bar $moo
=> bar moo 123
$ # so far so good but
$ ((foo++))
$ echo $foo $bar $moo
=> 123 moo 123

Now my chain of indirections is broken…

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]