0

I want to store matches of a find command into a file or variable, but matches should go into separate lines.

When I do files=$(find ./ -type f [match criteria]) then the matches will be separated by one space when I see the echo $files output:

./mounts.sh ./delete-data.sh ./test.sh

How can I store one result per line instead?

DEKKER
  • 834
  • 8
  • 18
  • You very seldom need to store separate pathnames in a single string. I'm assuming you want to _use_ the pathnames for something? If so, that could be done directly from `find`. Note too that `echo` outputs each of its arguments with spaces between them, and you're giving it a string for the shell to split up into multiple arguments. – Kusalananda Oct 07 '22 at 14:34
  • @Kusalananda yes I know I can directly do stuff with -exec, but I need to store the results in a file or variable in this particular case – DEKKER Oct 07 '22 at 14:36
  • 1
    You already do. The issue is that you're not quoting the string you use with `echo`. – Kusalananda Oct 07 '22 at 14:37

0 Answers0