From: Eric Cook <llua@gmx.com>
To: zsh-users@zsh.org
Subject: Re: [[ -f ]] and filename generation
Date: Sat, 16 Apr 2016 10:55:15 -0400 [thread overview]
Message-ID: <57125253.1090409@gmx.com> (raw)
In-Reply-To: <20160416113133.GA10973@solfire>
On 04/16/2016 07:31 AM, Meino.Cramer@gmx.de wrote:
> Hi,
>
> A script I am writing is reading filenames from a list.
> These filenames not complete.
>
> Example:
>
> On disk:
> filename.ext1.ext2
>
> In the list:
> filename
> or
> filename.ext
>
> I want to check for the existing of the files in the list on disk with
> a construct like this
>
> if [[ -f $FILEFROMLIST ]] ; then
>
> # do something more useful here
>
> fi
>
> I know, that are different approaches to this problem (for example
> reading the filenames from disk into an array and process those) but
> I am interested in getting this -f thingy to run.
>
> I tried variation of
> if [[ -f "$FILEFROMLIST*" ]] ; then .... fi
> with extendedglob set...but with no success.
>
> Is there any way to get this "-f" thingy to work?
>
> Thank you very much in advance for any help!
> Best regards,
> Meino
>
>
>
>
>
Filename generation does not happen inside the [[ normally.
In zsh >= 5.0.5, you can force globbing to happen by using the glob qualifier #q.
(requires extendedglob to be enabled)
% [[ -f *(#q.) ]]; echo $?
1
Since globbing can match multiple files, [[ -f will fail since more than one file
matches the glob. So you can also use the new qualifier Y to limit the results to
the first match.
% [[ -f *(#qY1.) ]]; echo $?
0
next prev parent reply other threads:[~2016-04-16 14:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-16 11:31 Meino.Cramer
2016-04-16 14:55 ` Eric Cook [this message]
2016-04-16 17:10 ` 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=57125253.1090409@gmx.com \
--to=llua@gmx.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).