zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
To: zsh-users@sunsite.dk
Subject: Re: rm nonexisting*; alias with parameters?
Date: Wed, 10 Aug 2005 21:06:18 +0100	[thread overview]
Message-ID: <20050810200620.E765C8633@pwstephenson.fsnet.co.uk> (raw)
In-Reply-To: Message from Deliverable Mail <deliverable@gmail.com>  of "Wed, 10 Aug 2005 12:18:53 PDT." <7c737f3005081012187ed74a81@mail.gmail.com>

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@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


  reply	other threads:[~2005-08-10 19:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <deliverable@gmail.com>
2005-08-10 19:18 ` Deliverable Mail
2005-08-10 20:06   ` Peter Stephenson [this message]
2005-08-10 20:31     ` Deliverable Mail
2005-08-10 22:51       ` Mikael Magnusson
2005-08-11  3:17         ` "splitting prpblem" Meino Christian Cramer
2005-08-11  8:40           ` Michal Politowski
2005-08-11 17:01             ` Meino Christian Cramer
2009-06-16  3:17 ` serverizing a fat process with named pipes Alexy Khrabrov
2009-06-16 20:29   ` Peter Stephenson
2009-06-17  0:47   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050810200620.E765C8633@pwstephenson.fsnet.co.uk \
    --to=pws@pwstephenson.fsnet.co.uk \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).