I was going through this What is the use of eval `opam config env` or eval $(opam env) and their difference? and notice something funny. I understand command subtitution is used to nest commands in zsh by evaluating a zsh cmd in a subshell and then giving it to the output as input to the command in front e.g.
eval $(cmd)
runs cmd replaces $(cmd)
and gives it to the command eval
. But when eval is not there is actually tries to interpret at string literal commands which to me is odd because if I gave that literal string to the termianl it would evaluate it just fine. e.g.
(iit_synthesis) brandomiranda~ ❯ $(echo v=1)
zsh: command not found: v=1
(iit_synthesis) brandomiranda~ ❯ v=1
(iit_synthesis) brandomiranda~ ❯ echo $v
1
interprets v=1
as a command to run but if I would have typed v=1
it would have evaluated and set the variable just fine. So what is the implicit command $(echo v=1)
is giving to?
e.g. if I added eval in this case it would have worked which is strange to me. I would have expected that if $(echo v=1)
just returns the string v=1
which is what we are echoing and then runs it in the terminal.
Note, eval at the front does work:
(iit_synthesis) brandomiranda~ ❯ echo vv=2
vv=2
(iit_synthesis) brandomiranda~ ❯ $(echo vv=2)
zsh: command not found: vv=2
(iit_synthesis) brandomiranda~ ❯ eval $(echo vv=2)
(iit_synthesis) brandomiranda~ ❯ echo $vv
2
related: