How can I make command substitution pass a list of single-quoted POSIX paths separated by spaces?command1 $(command2)command1 '/path/to/file 1' '/path/to/file 2' '/path/to/file 3'How can I trace the expansion?
Command substitution - single quotes and spaces
bash;command substitution
You can see exactly what command is being run by using set -x. A rather silly example:$ echo $(echo foo 'bar baz' taz\\ jaz)foo 'bar baz' taz\ jazwill give:++ echo 'foo '\''bar baz'\'' taz\ jaz'+ echo foo ''\''bar' 'baz'\''' 'taz\' jazfoo 'bar baz' taz\ jazThis is somewhat hard to read, because of all the escaping. For example, that second word:'' becomes nothing.\' becomes a single quote (')'bar' becomes barso that parameter is passed as 'bar. You can confirm with something like this (assuming you have Data::Dump installed, which isn't the default, unfortunately) Note the $(echo has been copied verbatim to the perl line:$ perl -MData::Dump=pp -E 'pp @ARGV' $(echo foo 'bar baz' taz\\ jaz)(foo, 'bar, baz', taz\\, jaz)What's happening here is that bash is doing word splitting (based off $IFS), not argument parsing. So you, unfortunately, probably have to use eval, and deal with all the risk that entails.$ eval echo $(echo foo 'bar baz' taz\\ jaz)foo bar baz taz jaz(Also, I'll note, if you can get your command to generate its output as a list of names, separated by NUL, that would be easy to deal with using xargs -0 and further, fully safe).