Sujet : Re: Executing Shell Pipelines with ?find? _-exec?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shell comp.os.linux.miscDate : 27. Apr 2024, 19:13:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240427110236.112@kylheku.com>
References : 1 2 3
User-Agent : slrn/pre1.0.4-9 (Linux)
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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca