help-bash
[Top][All Lists]
Advanced

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

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


From: Chris F.A. Johnson
Subject: Re: [Help-bash] Specifying multiple index numbers in array
Date: Fri, 3 May 2013 15:55:42 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

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, <http://cfajohnson.com/>
   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]