I was reading this question and answer: zsh - variable assignment isn't working. The post explains how to fix it, but not why. Why does the local variable assignment fail in that case ?
There are also some other examples of similar behaviour like this:
myfun()
{
local x=$(echo "a b"); echo ${x}
}
myfun2()
{
local x
x=$(echo "a b")
echo ${x}
}
myfun3()
{
local x=$(echo "a b")
echo ${x}
}
This results in the following output:
a
a b
a
If I put quotes around the 'x="$(echo "a b")" in all cases I get the correct variable assignment.
If I run the same thing in bash, I get 'a b' for all functions.
Can someone explain why bash and zsh are acting differently here ?