From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19265 invoked by alias); 4 Mar 2012 19:44:18 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16832 Received: (qmail 24357 invoked from network); 4 Mar 2012 19:44:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120304114412.ZM24769@torch.brasslantern.com> Date: Sun, 04 Mar 2012 11:44:12 -0800 In-reply-to: Comments: In reply to Mikael Magnusson "Re: if the file is not found the files is not found is the file not found" (Mar 4, 7:48pm) References: <20120304143102.GE18164@solfire> <120304103757.ZM24588@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: if the file is not found the files is not found is the file not found MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Mar 4, 7:48pm, Mikael Magnusson wrote: > > On 4 March 2012 19:37, Bart Schaefer 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