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 21468
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Use of variables in the <x-y> globbing mechanism
- Date: Thu, 21 Apr 2016 00:15:42 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=ymUgnoun9jqcnIRB6Z0LAvmyphsiAMEhWP/7TKltkso=; b=qh2V0hQiYReMODTp2NK50RsMvqoFKV0T8l7SBb6uahMAaEdiy7TmYxjLSOZ+EMuh/r 8Qa0Qr3LwlwHwIlhsfnyOVW+sUDH5yASq66BanlR795xHG/BZ66KWH1kipYkH7b31Me6 1l8QMCPQAIb2z6Sqb+DZOShXyqOXi6r82yTbpfHzLZlDPucx7f9jUDFb8+L/w60Tyjot hmWpscV2lNq+nVLnarl/KZxvSweMDG9e9qR5+PnjQS607SOzPMkZKq0kikn/LKR50myz WmVGEi6V2mbKOEzqL7YFhHpgvuk825ILV3RR+hB3O2Yk8MDl5yMVGx2zTGS9bKoxN9AC lv4A==
- In-reply-to: <5718642A.90505@gmail.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>
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}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author