I need to substitute output of find
command to another command to process every found file, e.g.:
mdls `find ~/target_dir/ -iname '*some*' -depth 1`
(mdls
is a command in OS X which get metadata attributes of the specified file. It doesn't support piping thus find ... | mdls
fails.)
The command above works fine, but expectedly fails on files with spaces in name. I thought that adding quotes via sed
helps with it:
$ find ~/target_dir/ -iname '*some*' -depth 1 | sed 's/\(.*\)/"\1"/'
"/Users/shau-kote/target_dir//secondsomefile"
"/Users/shau-kote/target_dir//some file with spaces in name"
"/Users/shau-kote/target_dir//somefile"
Alack, now my mdls
command fails on all files:
$ mdls `find ~/target_dir/ -iname '*some*' -depth 1 | sed 's/\(.*\)/"\1"/'`
"/Users/shau-kote/target_dir//secondsomefile": could not find "/Users/shau-kote/target_dir//secondsomefile".
How can I fix it so as mdls
do correctly process all file names from find
?
Thank you.
P.S. I'm not sure is it important or self-evident, but
mdls "/Users/shau-kote/target_dir//secondsomefile"
works properly.