From: "Nikolay Aleksandrovich Pavlov (ZyX)" <kp-pav@yandex.ru>
To: Bart Schaefer <schaefer@brasslantern.com>,
"zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: Use of variables in the <x-y> globbing mechanism
Date: Fri, 22 Apr 2016 14:05:59 +0300 [thread overview]
Message-ID: <7043971461323159@web25h.yandex.ru> (raw)
In-Reply-To: <160421001542.ZM15369@torch.brasslantern.com>
21.04.2016, 10:18, "Bart Schaefer" <schaefer@brasslantern.com>:
> On Apr 20, 10:24pm, Henman wrote:
> }
> } It would be very useful if the <x-y> globbing mechanism would work with
> } variables.
>
> It can't do so because <$x-$y> is valid redirection syntax, meaning to
> read from file "$x-$y" and write to whatever comes after. It's rare
> enough to have files with digit-digit names that it was deemed OK to
> break the redirection rules in that special case, but it would cause
> to many problems to generalize it.
>
> } # The from_number and to_number are read in from a list of files to process
> } and injected between a filename pattern's prefix and extension.
> }
> } for file in ${SFNPAT:r}-<${from_number}-${to_number}>.${SFNPAT:e}
>
> Use the {x..y} syntax:
>
> for file in ${SFNPAT:r}-{${from_number}..${to_number}}.${SFNPAT:e}
>
> This latter expands to the full list of names rather than globbing them,
> so it won't skip any missing files, but it will probably work in your
> example.
>
> If there may be gaps in the file sequence so you really do need to do
> the glob, put the entire expression in a variable like so:
>
> local slice="<${from_number}-${to_number}>"
> for file in ${SFNPAT:r}-${~slice}.${SFNPAT:e}
Variable can be avoided with the usual ${:-…} hack:
for file in ${SFNPAT:r}-${~${:-<$from_number-$to_number>}}.${SFNPAT:e}
prev parent reply other threads:[~2016-04-22 11:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-21 5:24 Henman
2016-04-21 7:15 ` Bart Schaefer
2016-04-22 11:05 ` Nikolay Aleksandrovich Pavlov (ZyX) [this message]
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=7043971461323159@web25h.yandex.ru \
--to=kp-pav@yandex.ru \
--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).