Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: script within find
- X-seq: zsh-users 11837
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Alexy Khrabrov <deliverable@xxxxxxxxx>
- Subject: Re: script within find
- Date: Fri, 14 Sep 2007 00:29:47 +0100
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <7c737f300709110052t5797209w8ac77cd4d3aa6c3f@xxxxxxxxxxxxxx>
- Mail-followup-to: Alexy Khrabrov <deliverable@xxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <7c737f300702232339keaffa58g99b1f51de74e0c8a@xxxxxxxxxxxxxx> <20070224100809.GA4828@xxxxxxxxxxxxxxx> <7c737f300704251214r602027a4u2d3533370fd317a9@xxxxxxxxxxxxxx> <20070425215214.GA8900@xxxxxxxxxxxxxxxxx> <20070425215843.GB8900@xxxxxxxxxxxxxxxxx> <7c737f300704251526m48df5c7dk6d32b340547e012d@xxxxxxxxxxxxxx> <17393e3e0704251538h10a32ff4xff95bb875d8ed193@xxxxxxxxxxxxxx> <7c737f300704251619y2566090cke411902726c27eec@xxxxxxxxxxxxxx> <7c737f300709110052t5797209w8ac77cd4d3aa6c3f@xxxxxxxxxxxxxx>
On Tue, Sep 11, 2007 at 09:52:19AM +0200, Alexy Khrabrov wrote:
> A while ago I asked about generalization of the nested command in find
> -exec. What if I have to execute a random series of shell commands
> for each file found by find and given to exec -- how should I package
> the series under zsh? I tried -exec (cmd1; cmd2; cmd3) and it seems
> not to work -- find complains about ( and ) and loses ; ... Is it a
> shell-sensitive problem or find-specific?
[...]
Like any other shell. Here, it's down to find syntax, not zsh
syntax.
So
find ... -exec cmd1 \; -exec cmd2 \; -exec cmd3 \;
But beware cmd2 will only be executed if cmd1 succeeds (returns
a non-null return code).
Or;
find ... -exec sh -c '
cmd1
cmd2
cmd3' \;
That's an inline script. If you want to pass arguments to that
script beware that the first one will be available as $0, not
$1. It's not true for very old or non standard shell, that's why
you sometimes find:
find ... -exec sh -c '
cmd1 -- "$1"
cmd2 -- "$1"' {} {} \;
Or if you want to user the + syntax to pass more than one file
path at the same time:
find ... -exec sh -c '
shift "$1"
for file
do cmd -- "$file"
done' 2 1 {} +
But with modern shs, you should be able to do:
find ... -exec sh -c '
cmd1 -- "$0"
cmd2 -- "$0"' {} \;
find ... -exec sh -c '
for file
do cmd -- "$file"
done' inline {} +
But with zsh, you generally no longer need find as zsh's
globbing can do almost everything find can do.
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author