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

Re: Help on filename generation

Peter Stephenson wrote:
> Joel J. Adamson wrote:
> > function doit() {
> >    for file in $1/*(generic)*~*(~)
> >    print $file
> >    exit
> > }
> > 
> > Currently I get "doit:1: unknown file attribute."   When I enter this
> > globbing pattern at the interactive prompt, I get the files I want.
> The pattern should be:
>  $1/*generic*~*\~

I've also just looked at the rest of the function and noticed:

- you also don't want that "exit" there.  That will
exit the whole shell that's calling the function.  "return" is the
command to use from functions.  However, simply falling off the end is

- you don't want both "function" *and* the "()", since they're doing the
same job.  You'll end up with a function called "function" that does the
samething as "doit".

- The for loop syntax is a bit confusing.  The short form will work, but
if the command to be executed isn't on the same line it's not obvious
which statements are inside the loop, and may confuse you when you edit
it, so I'd recommend avoiding it here.


doit() {
   for file in $1/*generic*~*\~
     print $file

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

To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview

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