Re: Executing Shell Pipelines with “find -exec”

Liste des GroupesRevenir à cu shell 
Sujet : Re: Executing Shell Pipelines with “find -exec”
De : naddy (at) *nospam* mips.inka.de (Christian Weisgerber)
Groupes : comp.unix.shell comp.os.linux.misc
Date : 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

Date Sujet#  Auteur
27 Apr 24 * Executing Shell Pipelines with “find -exec”8Lawrence D'Oliveiro
27 Apr 24 +* Re: Executing Shell Pipelines with “find -exec”6Christian Weisgerber
27 Apr 24 i+* Re: Executing Shell Pipelines with ?find? _-exec?4Robert Heller
27 Apr 24 ii`* Re: Executing Shell Pipelines with ?find? _-exec?3Kaz Kylheku
27 Apr 24 ii `* Re: Executing Shell Pipelines with ?find? _-exec?2Robert Heller
5 May 24 ii  `- Re: Executing Shell Pipelines with ?find? _-exec?1Friedhelm Waitzmann
28 Apr 24 i`- Re: Executing Shell Pipelines with “find -exec”1Lawrence D'Oliveiro
5 May 24 `- Re: Executing Shell Pipelines with “find -exec”1Friedhelm Waitzmann

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal