Sujet : Re: Long filenames in DOS/Windows and Unix/Linux
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.unix.programmerDate : 04. Sep 2024, 08:05:38
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vb90s2$3o2de$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Pan/0.160 (Toresk; )
On Tue, 03 Sep 2024 21:36:48 -0700, Keith Thompson wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
Next step: what if you wanted to handle newlines in file names as well?
Either `find ... -print0 | xargs -0 ...` or a quick Perl script.
Sure, it’s much easier in Perl or Python or some other such programming-
oriented (as opposed to command-oriented) language. But it can be done in
Bash.
The thing is, while find is handy for getting the matching file names,
xargs is not always the most convenient way of processing them. You often
just want to be able to do “for f in «filenames»; do «whatever» done”,
e.g.:
collect_expand «wildcard» found_filenames
for f in "${found_filenames[@]}"; do
echo "found" $(printf %q "$f")
done
That “collect_expand” is a Bash function. Do you want to figure out how to
write it, before I post my solution? ;)