zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: if the file is not found the files is not found is the file not found
Date: Sun, 4 Mar 2012 19:48:37 +0100	[thread overview]
Message-ID: <CAHYJk3SwbMnkWvHhn5oPih0kh_XmNtYh+s8CSWo=UQRYxFoURQ@mail.gmail.com> (raw)
In-Reply-To: <120304103757.ZM24588@torch.brasslantern.com>

On 4 March 2012 19:37, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mar 4,  3:31pm, meino.cramer@gmx.de wrote:
> }
> }      [ -f ${f}-[0-9]*.mp2 ]] && rm -f ${f}-[0-9]*.mp2
>
> This won't work even if the files do exist, because you can't apply
> a single "-f" test to the multiple files that result from the glob.
>
> Also you've used "[" on the left but "]]" on the right, which is
> mostly nonsense.  If you instead used [[ on the left then the glob
> would not be expanded and the test would again fail.
>
> On Mar 4,  3:37pm, Mikael Magnusson wrote:
> }
> } If you setopt extendedglob you can append (#qN) to the pattern
>
> You don't even need extendedglob -- you just need bare_glob_qual, which
> is on by default unless you're in sh/ksh emulation modes:
>
>    rm -f ${f}-[0-9]*.mp2(N)

Ah, I've had them both on since forever and knew extendedglob wasn't
on by default, so I assumed bareglobquals was also off.

> I'm sure the archives of zsh-users hold many different answers to the
> question, "Given a file pattern, how do I test whether at least one
> matching file exists?"  Unfortunately, there's really no way to do so
> in a single operation unless you set the no_nomatch option.  [[ ]]
> does not perform globbing, and the test operators such as [ -f ] are
> defined to return TRUE rather than FALSE on a *missing* file name
> operand, so null_glob is not sufficient.

Here's one more for the collection,
if () { (( $# )) } arglblargh*(N[1]); then echo yes; else echo no; fi

But this needs the 'new' anon functions with arguments support.

-- 
Mikael Magnusson


  reply	other threads:[~2012-03-04 18:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-04 14:31 meino.cramer
2012-03-04 14:36 ` Moritz Bunkus
2012-03-04 14:37 ` Mikael Magnusson
2012-03-04 18:37   ` Bart Schaefer
2012-03-04 18:48     ` Mikael Magnusson [this message]
2012-03-04 19:44       ` Bart Schaefer
2012-03-04 20:13         ` Mikael Magnusson
2012-03-04 21:47           ` Bart Schaefer
2012-03-05  0:48             ` Mikael Magnusson

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='CAHYJk3SwbMnkWvHhn5oPih0kh_XmNtYh+s8CSWo=UQRYxFoURQ@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /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).