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

Re: rm nonexisting*; alias with parameters?



Deliverable Mail wrote:
> I have a log directory where different logs appear, and an alias to
> clear it up.  I try to define patterns covering all the logs to avoid
> rm *, which is dangerous and asks for a confirmation.  So I define all
> possible patterns like in an alias, rml:
> 
> alias rml='rm prefix1.* *.suffix2*'
> 
> But when some of the patterns match nothing, zsh prints an error about
> that doesn't do anything.  How can I change that behavior to the
> expected of rm -f ?

(Did you miss the -f after the rm?  That confused me to begin with but
I'll assume so.  The shell can't make rm look like rm -f.)

I think what you want is that if some patterns *do* match, the ones that
don't are silently removed.  The neatest way of doing this is "setopt
cshnullglob", which uses the csh method:  if no patterns match, the
shell reports an error, whereas if some do, the others are removed.  If
you never want the shell error, "setopt nullglob".

> While I'm on the subject of aliases, looks like zsh aliases are as
> weak as bash's, so when I have my lr:
> 
> alias lr='ls -lt | head'
> 
> which I could not use with a parameter, lr <dir>, I still cannot use a
> parameter in zsh.  In bash,  made lr a function -- what the zsh
> function would look like?

The same, probably.

lr() {
  ls -lt "$@" | head
}

> And is there a way to do it in an alias, or still not?

No, functions are the right way.  This is exactly what they're for.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



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