The bash man says that variable expansion occurs before command substitution. I was seeking of an example that shows it clearly. So i tried this:
root@antec:/# var=1
root@antec:/# echo $(var=2; echo $var)
2
root@antec:/#
I was expecting bash to do:
1) replace $var by “1” in the substitution
2) execute echo $(var=2; echo 1)
Obviously this is not what bash is doing ..
Can someone please explain what is going one here ? And if someone has an example showing the precedence of variable expansion over command substitution it would be nice too
I do not know what the bash man page is talking about.
The POSIX specification for the shell says:
This makes it pretty clear that variable expansion (aka. "parameter expansion") happens at the same time as command expansion ("command substitution"), not before or after.
So I do not think the example you are asking for exists.