In short, I want to use directories listed by a command in a find
command:
find $(produces_dir_names --options...) -find-options...
The problem comes with white space in the directory names. I thought quoting them in the output of the producing command (which I can change) would be enough:
"a" "a b" "a b c"
but bash complains:
find: ‘"a"’: No such file or directory
find: ‘"a’: No such file or directory
find: ‘b"’: No such file or directory
find: ‘"a’: No such file or directory
find: ‘b’: No such file or directory
find: ‘c"’: No such file or directory
As you can, see bash
will split the output of the command on spaces, even with the quotation marks.
I tried to fiddle with IFS
and set it to \n
,
but my understanding of it seems too limited to get it working.
The only workaround I found was in this Stack Overflow question:
bash command substitution remove quotation,
namely putting an eval
in front of it, but this seems kind of ugly.
My Questions:
Is there an easy way and how would it look like to write this substitution, without the eval
?
Are the quotations even necessary?
Example (producing the same output):
find $(echo '"a" "a b" "a b c"')
ls
problem, also discussed extensively here. You might be able to find a way to make it work, but it's almost always going to be fraught. Also, settingIFS
to\n
isn't safe either, because filenames can contain\n
– Eric Renouf Oct 24 '16 at 17:56ls $(produces_dir_names --options...)
to see if find was not understanding the output of the substituion correctly. I changed the example output in my question. – ness Oct 24 '16 at 18:14