On 4/16/20 11:15 AM, tu...@posteo.de wrote:
> 
> Is there a way to express $fn in a way, so that
> do_something get one filename at a time and
> whole thing does not is torn apart by some
> not so nice filenames?
> 

What are your constraints... are you using bash, or just any POSIX
shell? Can you rely on GNU extensions to find/xargs, etc? Is
do_something a shell command or a program?

Even with bash, find/xargs tends to fall down if you need to run a
series of shell commands on each thing found. The simplest way to handle
that is to use "while read..." with the bash-specific null separator to
loop through the files one at a time, like in

https://gitweb.gentoo.org/proj/portage.git/tree/bin/install-qa-check.d/90bad-bin-owner

If you want it to be portable, on the other hand, I recently wasted
several hours on this problem and it's not pretty. Something like,

  find -name 'whatever' \
    -exec sh -c "
      for f in \"\${@}\"; do
        do_stuff \"\${f}\" && echo \"\${f}\"
      done
    " - {} +

will do it.

Reply via email to