1 |
On 4/16/20 11:15 AM, tuxic@××××××.de wrote: |
2 |
> |
3 |
> Is there a way to express $fn in a way, so that |
4 |
> do_something get one filename at a time and |
5 |
> whole thing does not is torn apart by some |
6 |
> not so nice filenames? |
7 |
> |
8 |
|
9 |
What are your constraints... are you using bash, or just any POSIX |
10 |
shell? Can you rely on GNU extensions to find/xargs, etc? Is |
11 |
do_something a shell command or a program? |
12 |
|
13 |
Even with bash, find/xargs tends to fall down if you need to run a |
14 |
series of shell commands on each thing found. The simplest way to handle |
15 |
that is to use "while read..." with the bash-specific null separator to |
16 |
loop through the files one at a time, like in |
17 |
|
18 |
https://gitweb.gentoo.org/proj/portage.git/tree/bin/install-qa-check.d/90bad-bin-owner |
19 |
|
20 |
If you want it to be portable, on the other hand, I recently wasted |
21 |
several hours on this problem and it's not pretty. Something like, |
22 |
|
23 |
find -name 'whatever' \ |
24 |
-exec sh -c " |
25 |
for f in \"\${@}\"; do |
26 |
do_stuff \"\${f}\" && echo \"\${f}\" |
27 |
done |
28 |
" - {} + |
29 |
|
30 |
will do it. |