[Top][All Lists]

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

Re: [Help-bash] Specifying multiple index numbers in array

From: Dan Douglas
Subject: Re: [Help-bash] Specifying multiple index numbers in array
Date: Fri, 3 May 2013 16:14:58 -0500

I've known about this. It's a nice effect. I expect the quotes to
cause a failure though. `: "$(("{1,2}"))"' isn't legal while `:
"$((_["{1,2}"]))"' and `: "${_["{1,2}"]}"' are despite the index
arithmetic being evaluated prior to quote removal. I'd ordinarily
approach similar problems using something like `: 0; echo
"${a[_+=2]"{,}"}"'. I can understand why that one works.

Perhaps the parser logic is shared with index evaluation for
associative arrays, where quote removal does occur despite quotes
being redundant in that context.

On Fri, May 3, 2013 at 2:55 PM, Chris F.A. Johnson <address@hidden> wrote:
> On Fri, 3 May 2013, Jerry wrote:
>> I thought I saw a way to do this; however, I cannot find that article.
>> Assume I have and array with 7 items.
>> declare -a FOO=(zero one two three four five six)
>> now, if I wanted to extract index 2 and index 4, how could I do it?
>> I could use ${FOO[2]} and ${FOO[4]}; however, I wanted to do it in a
>> simpler fashion, something like ${FOO[2][4]} or something similar. Is
>> it possible?
>   Use brace expansion:
> echo "${FOO["{2,4}"]}"
>   Note that the brace expression is not quoted.
> --
>    Chris F.A. Johnson, <>
>    Author:
>    Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
>    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

reply via email to

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