Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Use of variables in the <x-y> globbing mechanism
- X-seq: zsh-users 21478
- From: "Nikolay Aleksandrovich Pavlov (ZyX)" <kp-pav@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Use of variables in the <x-y> globbing mechanism
- Date: Fri, 22 Apr 2016 14:05:59 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1461323160; bh=1J31YCxjckHRnUkZcjART+lxo8fO+brKdIz486WzEuY=; h=From:To:In-Reply-To:References:Subject:Date; b=aiHnaZCT3IkcI63S7mqPrWQ9nLnL9hQWe4kviX662FKzGBVvsSaCNEU+3689Fs2m+ 8yVk3L0thCoBghgnGqoR5snGxlB5Em3mvGoRYQpFF613n8aDs++ZnTD7W1Dxho9qbT 22dzsQyW6k1GTqCqjMAiOUGr+YMXfZRhTpriR2xU=
- In-reply-to: <160421001542.ZM15369@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <5718642A.90505@gmail.com> <160421001542.ZM15369@torch.brasslantern.com>
21.04.2016, 10:18, "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>:
> 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}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author