* brace expansion in array subscript
@ 2014-07-27 19:57 Rory Mulvaney
2014-07-28 0:39 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Rory Mulvaney @ 2014-07-27 19:57 UTC (permalink / raw)
To: Zsh Users
Hi,
I'm wondering if it's possible to somehow specify a set of indices to an
array using brace expansion, to get a subset of the indices? To get
indices 2 and 5 of the array "arr", I'd like to use something like:
arr=( elt1 elt2 elt3 elt4 elt5 elt6 )
echo ${arr[{2,5}]}
Why doesn't that get expanded into "echo ${arr[2]} ${arr[5]}"?
It seems there would be lots of convenient uses of this feature.
Thanks in advance,
Rory
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: brace expansion in array subscript
2014-07-27 19:57 brace expansion in array subscript Rory Mulvaney
@ 2014-07-28 0:39 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2014-07-28 0:39 UTC (permalink / raw)
To: Zsh Users
On Jul 27, 2:57pm, Rory Mulvaney wrote:
}
} echo ${arr[{2,5}]}
}
} Why doesn't that get expanded into "echo ${arr[2]} ${arr[5]}"?
Array subscripts are already a comma-separated pair of arithmetic
expressions (or a quoted string value for associative arrays), and
curly braces already have their own special meaning in parameter
expansion expressions. The syntax for brace expansion doesn't fit
well here.
} It seems there would be lots of convenient uses of this feature.
If you really need it, you can get it this way:
echo ${(e):-\${arr[{2,5}]}}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-07-28 0:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-27 19:57 brace expansion in array subscript Rory Mulvaney
2014-07-28 0:39 ` Bart Schaefer
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).