I want to substitute an echo
command followed with |
(pipe). For example,
$(echo "echo 'hello' | cat")
returns
'hello' | cat
I expect this to behave like
echo 'hello' | cat
which returns
hello
but that's not the case. Why?
PS. I'm aware of eval
, and
eval $(echo "echo 'hello' | cat")
works as expected
echo $(var=$((1+2+3)); echo $var)
does echo a6
. – Jun 07 '22 at 15:38var
gets assigned the value6
, and the stuff inside the command substitution runs in a single subshell, so the variable keeps that value for the duration of that subshell, if one wants to make a convoluted command substitution like that. None of that contradicts anything I said here, though. – ilkkachu Jun 07 '22 at 19:06$(echo $((a+b)) )
or$(( $(somecmd) + 3))
. Nested expansions work fine. What I wrote above was about the results of the expansions being scanned for further expansions, that doesn't happen, the same way the shell doesn't scan the results of expansions for operators like|
. That was what the question was about anyway. – ilkkachu Jun 07 '22 at 21:09