Shell is: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
I'm considering the following command line:
a=1; echo $a$((a=2))$a
The output is:
122
I deduct that the expansion is processed in the following order:
- The variable
a
is assigned the value1
; - The first
$a
is expanded via paramet expansion witha=1
- Then arithmetic expansion of
$((a=2))
is performed, settinga
to2
, - Then the second
$a
is expanded with new value ofa
that was set to2
at arithmetic expansion.
If my understand is correct, that processing order means that the shell circles back to parameter expansion after having proceeded to arithmetic expansion.
And this contradicts my understanding of the GNU bash manual which states that there is clear order in bash expansion: arithmetic expansion being performed AFTER parameter expansion.
Is someone able to explain what's at play here?