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

Re: Style question: Can this be written in a more elegant way?



On Apr 25,  9:55am, Marc Chantreux wrote:
} Subject: Re: Style question: Can this be written in a more elegant way?
} 
} > } file=( *(om) )
} > } ((  $file[1] )) && PROG_SUCCESS || PROG_FAIL
} > 
} > I think you mean:
} > 
} >     file=( X*(Nom[1]) )
} >     (( $+file )) && PROG_SUCCESS $file || PROG_FAIL
} 
} I didn't : my lines was the best i've found.

But (( $file[1] )) can't be right; it treats the file name as a math
expression, so a file named "3-3" would execute PROG_FAIL.  You must
at least mean (( ${+file[1]} )).

} is there a reason to not use the next line ?
} 
} if (( $+file )) { PROG_SUCCESS $file } else { PROG_FAIL }

It's a syntax error in other Bourne-like shells, and some of us are
habituated to write the portable constructs even when we're mixing
them with non-portable ones.
 
} BTW, i've tried another way to launch PROG_SUCCESS for the first file 
} but it failed because it execute the e:: code for all the files. Peraps 
} there is a trick i missed?

No, the meaning of (e:...:) is that the result of executing the commands
determines whether or not the file participates in the glob result.  So
the commands must be executed for every file, and this happens before
the sorting.

In this example ...

} % ls
} is  score  the  this
} % : *(Nom[1]e:echo last file $REPLY:)
} last file score
} last file score
} last file score
} last file score

... you have failed to quote $REPLY so it substitutes the value that it
had before the glob began to execute.  It's as if you had typed:

% : *(Nom[1]e:echo last file score:)

Correct is like so:

% : *(Nom[1]e:'echo last file $REPLY':)
last file this
last file is
last file the
last file score



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