Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: script within find
- X-seq: zsh-users 11447
- From: "Alexy Khrabrov" <deliverable@xxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: script within find
- Date: Wed, 25 Apr 2007 12:14:39 -0700
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=HEJZh75MaxQb7bwB+2/OWd6owCrYT4X0LiD+AEyDcHtCzz9LHaOdV9brsmJNQLVrO/Y6zuJM018kaxv04+4lOqOWanqL/tFVfkHpcXFE+n4v46h2Vhmzz9wEH6G2dDZ6EjdoO+Qs2Qj9JXKtwpJ/yWCkz/yN+oE5CvQxzkJPTNE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UZQGxbh4vz6dxZxQqMF09cMyMquv5L+aRs9LvYCg9HyBiNi8n5tvGOP2PHBlUnKb1mZg2of1P4DyT9SKMisveZGgKeejIZ/SOAEf/F/uZYpTA1J9pD5LN38Sf0dJhZ77u5o9D4zY0aMiXE0cAi5V44Tq/R3CycEdC6D4RcSsmCU=
- In-reply-to: <20070224100809.GA4828@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <7c737f300702232339keaffa58g99b1f51de74e0c8a@xxxxxxxxxxxxxx> <20070224100809.GA4828@xxxxxxxxxxxxxxx>
A while ago, Stephane suggested a terrific script on doing things
right inside find's exec.
I'm using that magic advice and it works, fantastic! Still it's a bit
of a mystery to me. Why do we need {} {} twice -- although there's
only one parameter reference to $1?
Also, how would I generalize it for two commands inside the script?
Here's an example. I want to convert a bunch of .tif files to .jpg's.
The original tifs reside in certain directory structure which should
be preserved in the target directory.
That is, we have something like
tifs/
dir1/
A.tif
B.tif
dir2/
C.tif
...
And we need to create
jpgs/
dir1/
A.jpg
B.jpg
dir2/
C.jpg
...
The command to do a single conversion is
convert -quality 100 dir1/A.tif /jpgs/dir1/A.jpg
-- however, we must ensure
mkdir -p /jpgs/`dirname {}` # or some such
-- before we invoke convert with the target path, to make sure it exists.
How can I stick *two* commands inside the exec in a find?
Cheers,
Alexy
On 2/24/07, Stephane Chazelas <Stephane_Chazelas@xxxxxxxx> wrote:
On Fri, Feb 23, 2007 at 11:39:40PM -0800, Alexy Khrabrov wrote:
> Here's a mystery solving which I've avoided for a while. Now that I'm
> going to publish a recipe for fixing Photoshop installation on a
> case-sensitive Mac drive, I'd like to compress it into one script.
>
> The problem is, the script contains a find command, which passes all
> things it finds via -exec to a small helper script. The helper script
> is necessary since it seems difficult to make -exec contain a single
> in-line command to do it. Here they are:
>
> -- the find command:
>
> find . -name a -exec ~/bin/fix-ps-cs2.sh {} \;
>
> -- the helper script, ~/bin/fix-ps-cs2.sh:
>
> #!/bin/sh
> DIR=`dirname $1`
> (cd $DIR; ln -s a A)
>
> as you see, it needs to invoke dirname on the argument, then create a
> symlink in that dirname.
>
> Can the helper script be avoided and all the work done within the
> single find command?
[...]
Not sure what that has to do with zsh, but on MAC OSX, I'd
expect find to have a -execdir:
find . -name a -execdir ln -s a A \;
Otherwise:
find . -name a -exec sh -c 'ln -s a "${1%a}A"' {} {} \;
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author