Sujet : Re: Executing Shell Pipelines with “find -exec”
De : naddy (at) *nospam* mips.inka.de (Christian Weisgerber)
Groupes : comp.unix.shell comp.os.linux.miscDate : 27. Apr 2024, 15:40:52
Autres entêtes
Message-ID : <slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>
References : 1
User-Agent : slrn/1.0.3 (FreeBSD)
On 2024-04-27, Lawrence D'Oliveiro <
ldo@nz.invalid> wrote:
find . -name \*.blend -exec \
sh -c '[ $(blendfile_version {} | jq -r .version ) \> 304 ]' \; \
-print
This is problematic because the filename is simply interpolated
into the command string, which is then interpreted by sh. If the
filename contains whitespace or shell meta-characters, the results
will be unexpected. Surrounding the {} with quotes doesn't fix
this completely, because the filename could contain a quote character.
A few days ago, Helmut Waitzmann pointed out a better solution over
on the German group:
find . -name \*.blend -exec sh -c \
'[ $(blendfile_version "$1" | jq -r .version ) \> 304 ]' sh {} \; \
-print
You pass the filename as a positional parameter and reference it
as such in the command string.
-- Christian "naddy" Weisgerber naddy@mips.inka.de