Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: iterating through a hierarchy with a filter



On Tue, 15 Apr 2008 01:33:53 +0200
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> On 2008-04-14 14:39:25 -0700, Alexy Khrabrov wrote:
> > If I give a single existing script as a parameter, it works fine.  If,  
> > however, I give it
> >
> > walk 'iconv -f utf8 -t cp1251' srcdir tgtdir ...
> >
> > -- I get "command not found" for 'iconv -f utf8 -t cp1251' at the line  
> > above.
> 
> You need to do sh word-splitting on $1 and make $filter an array:
> 
> filter=(${=1})
> 
> Alternatively, you can enable sh word-splitting globally.

That should work fine in this case.

More generally, I would be inclined to take the attitude that the argument
to your script is a complete command line in itself.  In that case, the
logical thing to do is to "eval" the variable that contains it.  That means
that you can put anything there you would in a normal zsh command line.  If
you want the command to be executed "at arm's length", put the eval inside
parentheses:

(eval $1) <input >output

I have a vague memory that the shell is smart enough only to fork once
if there's a single external command in the eval, but the mists of time may
be confusing me.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author