bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it possible or RFE to expand ranges of *arrays*


From: John Kearney
Subject: Re: Is it possible or RFE to expand ranges of *arrays*
Date: Sat, 28 Apr 2012 09:42:16 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120420 Thunderbird/12.0

Am 28.04.2012 05:05, schrieb Linda Walsh:


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*)


I "always" quote not sure why I didn't that time.
Except that it was just a quick response to a simple question.
but of course your right.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]