|
| From: | Linda Walsh |
| Subject: | Re: Is it possible or RFE to expand ranges of *arrays* |
| Date: | Fri, 27 Apr 2012 20:05:34 -0700 |
| User-agent: | Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666 |
Maarten Billemont wrote:
On 26 Apr 2012, at 06:30, John Kearney wrote:Am 26.04.2012 06:26, schrieb Linda Walsh:I know I can get a="abcdef" echo "${a[2:4]}" = cde how do I do: typeset -a a=(apple berry cherry date); then get: echo ${a[1:2]} = "berry" "cherry" ( non-grouped args) I tried to do it in a function and hurt myself.echo ${a[@]:1:2}I see little reason to ask bash to wordsplit the elements after expanding them.
You ought to quote that expansion.
---
Good point.
Since if you do:
> a=( 'apple pie' 'berry pie' 'cherry cake' 'dates divine')
> b=( ${a[@]:1:2} )
> echo ${#b[*]}
4
#yikes!
> b=( "${a[@]:1:2}" )
2
#woo!
I'd guess the original poster probably figured, I'd figure out the correct
form pretty quickly in usage. but thanks for your insight.
( (to all)....*sigh*)
| [Prev in Thread] | Current Thread | [Next in Thread] |