I have two test cases in zsh
A. without quotes
~$ y=(${(f)$(echo -e "a b\nc d")}); printf "<%s>\n" "${y[@]}"
<a b c d>
B. with quotes
~$ y=(${(f)"$(echo -e "a b\nc d")"}); printf "<%s>\n" "${y[@]}"
<a b>
<c d>
However if I first assign the output of echo
to a variable, the quotes do not have any effect:
C. without quotes
~$ x=$(echo -e "a b\nc d"); y=(${(f)${x}}); printf "<%s>\n" "${y[@]}"
<a b>
<c d>
D. with quotes
~$ x=$(echo -e "a b\nc d"); y=(${(f)"${x}"}); printf "<%s>\n" "${y[@]}"
<a b>
<c d>
Questions:
After some experiment, I feel the following rules may have been applied
A. without quotes
~$ y=(${(f)$(echo -e "a b\nc d")}); printf "<%s>\n" "${y[@]}"
<a b c d>
unquoted $()
produces words split by IFS
: see http://zsh.sourceforge.net/Doc/Release/Expansion.html#Command-Substitution
B. with quotes
~$ y=(${(f)"$(echo -e "a b\nc d")"}); printf "<%s>\n" "${y[@]}"
<a b>
<c d>
quoted $()
produces a single string
C. without quotes
~$ x=$(echo -e "a b\nc d"); y=(${(f)${x}}); printf "<%s>\n" "${y[@]}"
<a b>
<c d>
when being assigned to a scalar, it works as automatically quoted
D. with quotes
~$ x=$(echo -e "a b\nc d"); y=(${(f)"${x}"}); printf "<%s>\n" "${y[@]}"
<a b>
<c d>
when being assigned to a scalar, it works as automatically quoted
y=($(echo -e "a b\nc d"))
Follows Sec1 http://zsh.sourceforge.net/Doc/Release/Expansion.html#Command-Substitution