Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Thrashing is just virtual crashing.


devel / comp.unix.shell / Executing Shell Pipelines with “find -exec”

SubjectAuthor
* Executing Shell Pipelines with “find -exec”Lawrence D'Oliveiro
+* Re: Executing Shell Pipelines with “find -exec”Christian Weisgerber
|+* Re: Executing Shell Pipelines with ?find? _-exec?Robert Heller
||`* Re: Executing Shell Pipelines with ?find? _-exec?Kaz Kylheku
|| `* Re: Executing Shell Pipelines with ?find? _-exec?Robert Heller
||  `- Re: Executing Shell Pipelines with ?find? _-exec?Friedhelm Waitzmann
|`- Re: Executing Shell Pipelines with “find -exec”Lawrence D'Oliveiro
`- Re: Executing Shell Pipelines with “find -exec”Friedhelm Waitzmann

1
Executing Shell Pipelines with “find -exec”

<v0ig4l$96sa$1@dont-email.me>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8094&group=comp.unix.shell#8094

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell,comp.os.linux.misc
Subject: Executing Shell Pipelines with “find -exec”
Date: Sat, 27 Apr 2024 09:22:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <v0ig4l$96sa$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 27 Apr 2024 11:22:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="9e4fadc78fe91d749786c6f98d388f78";
logging-data="301962"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Uo8uYWy/PgFi5d7cwq+gX"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:NRZ6PUHePAC5BqfQy3CZXsUyats=
 by: Lawrence D'Oliv - Sat, 27 Apr 2024 09:22 UTC

The “find” command <https://manpages.debian.org/1/find.en.html> offers
a great variety of ways to filter out files. And if none of them is
quite good enough, you can use the “-exec” option to execute an
arbitrary command.

Unfortunately, it must be an arbitrary *single* command.

For example, I wanted to identify .blend files created by Blender
versions after 3.4. I have a command called “blendfile_version”
<https://gitlab.com/ldo/blender-useful/> which will output some basic
version information about a .blend file in JSON format. From this,
it’s easy enough to extract the version string with

blendfile_version «blendfile» | jq -r .version

and then filter out older versions with

test $(blendfile_version «blendfile» | jq -r .version) -gt 304

But this command cannot be used as is with -exec! That is, if I try

find . -name \*.blend -exec test $(blendfile_version {} | jq -r .version) -gt 304 \; -print

that won’t work, because -exec will not feed the command to a shell to
handle the command substitution, pipelining etc.

However, you can explicitly invoke a shell and give it a one-shot
command with “sh -c”. While the command string must be a single word,
it is possible to have multiple argument words following this command.
So if the command happens to be “eval”, that gives you your ability to
feed the separate words of the -exec command to the shell, thus:

find . -name \*.blend -exec sh -c 'eval "${@}"' \
sh test \$\( blendfile_version {} \| jq -r .version \) -gt 304 \; -print

This works, but it assumes that the find command will only substitute
the “{}” sequence with the file name if it occurs as a separate word.
In fact, GNU find will perform this substitution even if the sequence
occurs as part of a word. This allows the -exec command to be
simplified somewhat, by getting rid of the “eval” stage:

find . -name \*.blend -exec \
sh -c '[ $(blendfile_version {} | jq -r .version ) \> 304 ]' \; \
-print

And there we have it. Some commands have a “quiet” option, where you
give them a criterion to match, and they return an exit status
indicating success/failure to match (e.g. “grep -q”). Having this may
make use with find just a little bit easier, but as you can see, it’s
not strictly necessary.

Re: Executing Shell Pipelines with “find -exec”

<slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8095&group=comp.unix.shell#8095

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Path: i2pn2.org!i2pn.org!nntp.comgw.net!weretis.net!feeder8.news.weretis.net!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell,comp.os.linux.misc
Subject: Re: Executing Shell Pipelines with “find
_-exec”
Date: Sat, 27 Apr 2024 13:40:52 -0000 (UTC)
Message-ID: <slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>
References: <v0ig4l$96sa$1@dont-email.me>
Injection-Date: Sat, 27 Apr 2024 13:40:52 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="19003"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Sat, 27 Apr 2024 13:40 UTC

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

Re: Executing Shell Pipelines with ?find? _-exec?

<lpGcnb38WpoNg7D7nZ2dnZfqnPGdnZ2d@giganews.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8096&group=comp.unix.shell#8096

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Path: i2pn2.org!i2pn.org!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 27 Apr 2024 15:49:36 +0000
MIME-Version: 1.0
From: heller@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.17)
Subject: Re: Executing Shell Pipelines with ?find? _-exec?
In-Reply-To: <slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>
References: <v0ig4l$96sa$1@dont-email.me>
<slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>
Newsgroups: comp.unix.shell,comp.os.linux.misc
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <lpGcnb38WpoNg7D7nZ2dnZfqnPGdnZ2d@giganews.com>
Date: Sat, 27 Apr 2024 15:49:36 +0000
Lines: 34
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-2p64oipUGpu97qruhfimgV8uFDFcHkGMvnNX1R0uK+Tt13LUtMUVcdMa4qiLE8hqIEKGTVhRCKXtWjY!a7U6VgkB/rvVWeHK9Y/Zs8fByv43hyhxO2bgCfIjOhEMFsUfKMds3t76zIHpQFptX8I0pf7PTKuI!k0o=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: Robert Heller - Sat, 27 Apr 2024 15:49 UTC

Another option: find ... -print0 | xargs -0 -n 1 ...

At Sat, 27 Apr 2024 13:40:52 -0000 (UTC) Christian Weisgerber <naddy@mips.inka.de> wrote:

>
> 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.
>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

Re: Executing Shell Pipelines with ?find? _-exec?

<20240427110236.112@kylheku.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8097&group=comp.unix.shell#8097

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell,comp.os.linux.misc
Subject: Re: Executing Shell Pipelines with ?find? _-exec?
Date: Sat, 27 Apr 2024 18:13:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <20240427110236.112@kylheku.com>
References: <v0ig4l$96sa$1@dont-email.me>
<slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>
<lpGcnb38WpoNg7D7nZ2dnZfqnPGdnZ2d@giganews.com>
Injection-Date: Sat, 27 Apr 2024 20:13:26 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3b57bd4a52cf8401a2be99b40cc84e8f";
logging-data="545074"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dJA77f12v6Oo9zN9XC3xWd4fStd9RZZg="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:pFsdyupeaKIua6SBYX3rJ5CDv1Q=
 by: Kaz Kylheku - Sat, 27 Apr 2024 18:13 UTC

On 2024-04-27, Robert Heller <heller@deepsoft.com> wrote:
> At Sat, 27 Apr 2024 13:40:52 -0000 (UTC) Christian Weisgerber <naddy@mips.inka.de> wrote:
>> 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.
>
> Another option: find ... -print0 | xargs -0 -n 1 ...

And what is the ... after xargs? The goal of the command is
to print only those files F that individually satisfy the predicate
"[ $(blendfile_version F | jq -r .version) -gt 304 ]".

xargs will turn groups of files into command arguments, so
now you have to iterate over them; something like:

.. | xargs sh 'for x in "$@"; do\
[ $(blendfile_version "$x" | \
jq -r .version ) -gt 304 ] && printf "%s\n" "$x"
done'

It doesn't seem like an improvement. It does at least as much work
(still has to dispatch blendfile_version as many times as there
are files). It's more verbose, and uses GNU extensions.

If extensions are allowed, we can just drop find entirely and use
use double star globbing in Bash or any other shell that has it:

for x in **/*.blend; do
[ $(blendfile_version "$x" | jq -r .version ) -gt 304 ] && printf "%s\n" "$x"
done

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Executing Shell Pipelines with ?find? _-exec?

<WcWcnTF4lPG60rD7nZ2dnZfqnPidnZ2d@giganews.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8098&group=comp.unix.shell#8098

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Path: i2pn2.org!i2pn.org!weretis.net!feeder9.news.weretis.net!border-4.nntp.ord.giganews.com!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 27 Apr 2024 19:16:55 +0000
MIME-Version: 1.0
From: heller@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.17)
Subject: Re: Executing Shell Pipelines with ?find? _-exec?
In-Reply-To: <20240427110236.112@kylheku.com>
References: <v0ig4l$96sa$1@dont-email.me>?
<slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>?
<lpGcnb38WpoNg7D7nZ2dnZfqnPGdnZ2d@giganews.com>
<20240427110236.112@kylheku.com>
Newsgroups: comp.unix.shell,comp.os.linux.misc
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <WcWcnTF4lPG60rD7nZ2dnZfqnPidnZ2d@giganews.com>
Date: Sat, 27 Apr 2024 19:16:55 +0000
Lines: 61
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-HFM1UdVXqXoTglsKNpsJCk6YhF8+svZX09AX9H6X6t8bQJmgtGlhedKImbwwJaAQA2ORHphT4/7IVFT!n6gpqbx+Sa+gSweok7BygMyZZxFOO1SxwUeb2cTZKvkZq6SyHRK3JfvRCO9AOVgTEqwTcDLBLwY6!s94=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: Robert Heller - Sat, 27 Apr 2024 19:16 UTC

At Sat, 27 Apr 2024 18:13:25 -0000 (UTC) Kaz Kylheku <643-408-1753@kylheku.com> wrote:

>
> On 2024-04-27, Robert Heller <heller@deepsoft.com> wrote:
> > At Sat, 27 Apr 2024 13:40:52 -0000 (UTC) Christian Weisgerber <naddy@mips.inka.de> wrote:
> >> 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.
> >
> > Another option: find ... -print0 | xargs -0 -n 1 ...
>
> And what is the ... after xargs? The goal of the command is
> to print only those files F that individually satisfy the predicate
> "[ $(blendfile_version F | jq -r .version) -gt 304 ]".
>
> xargs will turn groups of files into command arguments, so
> now you have to iterate over them; something like:
>
> .. | xargs sh 'for x in "$@"; do\
> [ $(blendfile_version "$x" | \
> jq -r .version ) -gt 304 ] && printf "%s\n" "$x"
> done'
>
> It doesn't seem like an improvement. It does at least as much work
> (still has to dispatch blendfile_version as many times as there
> are files). It's more verbose, and uses GNU extensions.

The '-n 1' tells xargs to run the command given to xargs with only one file at
a time. There is no need for the "for x in "$@"; do...".

find . -name '*.blend' -print0 | xargs -0 -n 1 'sh [ $(blendfile_version "$1" | \
jq -r .version ) -gt 304 ] && printf "%s\n" "$1"'

The combination of find's -print0 and xargs -0 is to pass the names as nul
terminated strings rather then newline separated strings. This avoids problems
with file names containing characters that the shell with try to make sense of
(eg spaces, etc.).

>
> If extensions are allowed, we can just drop find entirely and use
> use double star globbing in Bash or any other shell that has it:
>
> for x in **/*.blend; do
> [ $(blendfile_version "$x" | jq -r .version ) -gt 304 ] && printf "%s\n" "$x"
> done
>
>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

Re: Executing Shell Pipelines with “find -exec”

<v0jv7l$k8gh$4@dont-email.me>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8099&group=comp.unix.shell#8099

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell,comp.os.linux.misc
Subject: Re: Executing Shell Pipelines with
“find -exec”
Date: Sat, 27 Apr 2024 22:46:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <v0jv7l$k8gh$4@dont-email.me>
References: <v0ig4l$96sa$1@dont-email.me>
<slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 28 Apr 2024 00:46:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="204de98df41bd5ef7b37f05a187c8914";
logging-data="664081"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Cxin/HW3y9NLu5EFamVBd"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:xHXklcIbSqOsZj6WTR/uK6dGDNU=
 by: Lawrence D'Oliv - Sat, 27 Apr 2024 22:46 UTC

On Sat, 27 Apr 2024 13:40:52 -0000 (UTC), Christian Weisgerber wrote:

> 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.

That is true. I only realized it later, after posting.

> You pass the filename as a positional parameter and reference it as such
> in the command string.

Another possibility might be to use an environment variable. I have done
this in other scripts.

Re: Executing Shell Pipelines with ?find? _-exec?

<j13jgk-p2u.ln1@foechtelwenk.news.arcor.de>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8100&group=comp.unix.shell#8100

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Followup: comp.unix.shell
Path: i2pn2.org!rocksolid2!news.nk.ca!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: usenetf24.effweh@erine.email (Friedhelm Waitzmann)
Newsgroups: comp.unix.shell,comp.os.linux.misc
Subject: Re: Executing Shell Pipelines with ?find? _-exec?
Followup-To: comp.unix.shell
Date: Sun, 5 May 2024 03:12:51 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <j13jgk-p2u.ln1@foechtelwenk.news.arcor.de>
References: <v0ig4l$96sa$1@dont-email.me> <slrnv2q034.ihq.naddy@lorvorc.mips.inka.de> <lpGcnb38WpoNg7D7nZ2dnZfqnPGdnZ2d@giganews.com> <20240427110236.112@kylheku.com> <WcWcnTF4lPG60rD7nZ2dnZfqnPidnZ2d@giganews.com>
Reply-To: Friedhelm Waitzmann <usenet24.effweh@erine.email>
Injection-Date: Sun, 05 May 2024 20:29:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0bc504b9da9524f0c0aceee4555ad3db";
logging-data="2112058"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xinfw1KjCQWrVNj05Y5LplxLg7pkvEts="
Cancel-Lock: sha1:p+eO6q5724zif2WFet6AHrvUeN0=
sha1:oEU+c6K9pePRHvBfAQoRvYoNJ0M=
 by: Friedhelm Waitzmann - Sun, 5 May 2024 01:12 UTC

Robert Heller <heller@deepsoft.com>:

>The '-n 1' tells xargs to run the command given to xargs with only one file at
>a time. There is no need for the "for x in "$@"; do...".

>find . -name '*.blend' -print0 | xargs -0 -n 1 'sh [ $(blendfile_version "$1" | \
> jq -r .version ) -gt 304 ] && printf "%s\n" "$1"'

You mean:

find . -name '*.blend' -print0 | xargs -0 -n 1 sh -c '[ $(blendfile_version "$1" | \
jq -r .version ) -gt 304 ] && printf "%s\n" "$1"' sh

Followup-To!

Re: Executing Shell Pipelines with “find -exec”

<8l1jgk-p2u.ln1@foechtelwenk.news.arcor.de>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=8101&group=comp.unix.shell#8101

  copy link   Newsgroups: comp.unix.shell comp.os.linux.misc
Followup: comp.unix.shell
Path: i2pn2.org!rocksolid2!news.nk.ca!2.eu.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: usenetf24.effweh@erine.email (Friedhelm Waitzmann)
Newsgroups: comp.unix.shell,comp.os.linux.misc
Subject: Re: Executing Shell Pipelines with
“find_-exec”
Followup-To: comp.unix.shell
Date: Sun, 5 May 2024 02:49:12 +0200
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <8l1jgk-p2u.ln1@foechtelwenk.news.arcor.de>
References: <v0ig4l$96sa$1@dont-email.me>
Reply-To: Friedhelm Waitzmann <usenet24.effweh@erine.email>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sun, 05 May 2024 20:29:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0bc504b9da9524f0c0aceee4555ad3db";
logging-data="2112058"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/I77MGEKZAovhZHR2+7NF0E0Wg4QNObW0="
Cancel-Lock: sha1:iePbPz7atjAIO6Xsidt3HwQUGdk=
sha1:MnBItrDcwEXLRYrsCuUKsL+fJ+U=
 by: Friedhelm Waitzmann - Sun, 5 May 2024 00:49 UTC

Lawrence D'Oliveiro <ldo@nz.invalid>:

>However, you can explicitly invoke a shell and give it a one-shot
>command with “sh -c”. While the command string must be a single word,
>it is possible to have multiple argument words following this command.
>So if the command happens to be “eval”, that gives you your ability to
>feed the separate words of the -exec command to the shell, thus:

> find . -name \*.blend -exec sh -c 'eval "${@}"' \
> sh test \$\( blendfile_version {} \| jq -r .version \) -gt 304 \; -print

>This works

No, it does not: What happens if find comes upon a file
“Adam & Eve.blend” or “;rm -rf -- "$HOME";.blend”? Yes, the
latter is a valid filename too! If you fill a filename into a
command string without recoding the filename to a notation of a
literal string, you can trick the command string to do things
that you did not have in mind.

I would rather put it this way:

find . -name \*.blend -exec sh -c \
'test "$( blendfile_version "$1" | jq -r .version )" -gt 304' \
sh {} \; -print

Here, find will replace the “{}” with the filename encountered
and give it as a positional parameter to the shell. Therefore it
must not and need not be quoted.

>GNU find will perform this substitution even if the sequence
>occurs as part of a word. This allows the -exec command to be
>simplified somewhat, by getting rid of the “eval” stage:

> find . -name \*.blend -exec \
> sh -c '[ $(blendfile_version {} | jq -r .version ) \> 304 ]' \; \
> -print

Again, this does not work with these two mindfully chosen
filenames.

The solution: Let find give the name that it comes upon as
a positional parameter to the shell:

find … -exec sh -c … sh {} \;

Please pay attention to Followup-To.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor