zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: if the file is not found the files is not found is the file not found
Date: Sun, 04 Mar 2012 11:44:12 -0800	[thread overview]
Message-ID: <120304114412.ZM24769@torch.brasslantern.com> (raw)
In-Reply-To: <CAHYJk3SwbMnkWvHhn5oPih0kh_XmNtYh+s8CSWo=UQRYxFoURQ@mail.gmail.com>

On Mar 4,  7:48pm, Mikael Magnusson wrote:
>
> On 4 March 2012 19:37, Bart Schaefer <schaefer@brasslantern.com> wrote:
> > 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?"
> 
> Here's one more for the collection,
> if () { (( $# )) } arglblargh*(N[1]); then echo yes; else echo no; fi

Yes, I was thinking about that but it doesn't capture the "is a plain
file" semantics of [[ -f ]] -- which you can fix by adding qualifiers
to the glob instead, of course -- and even my formulation falls down
if the glob matches a mix of plain and not-plain files and the first
one happens to be the wrong kind.

(Also, the [1] in your formula is extraneous, but that's a nit.)

Really what one means with [ -f foo* ] is usually one of

# One existing file matching foo* is a plain file
(){ local f; for f; do [ -f "$f" ] && return 0; done; return 1; } foo*(N)

or

# All files matching foo* exist and are plain files
(){ local f; for f; do [ -f "$f" ] || return 1; done; (( $# )); } foo*(N)

Still another way to do "one foo* is plain":

(){ (( $# )) } foo*(Ne:'[ -f "$REPLY" ]':)

I'm not sure there's a way to use (e::) for "every foo* is plain".

-- 
Barton E. Schaefer


  reply	other threads:[~2012-03-04 19:44 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
2012-03-04 19:44       ` Bart Schaefer [this message]
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=120304114412.ZM24769@torch.brasslantern.com \
    --to=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).