BashScripts.org
http://bashscripts.org/forum/

Array content as array name
http://bashscripts.org/forum/viewtopic.php?f=16&t=1220
Page 1 of 1

Author:  gianlu [ Fri Oct 08, 2010 4:02 am ]
Post subject:  Array content as array name

Hi all,

I'm trying to use a content of an array like array name but, doesn't work :(

this is my code:

Code:
groups[0]=group0
groups[1]=group1

group0[0]=value00
group0[1]=value01

group1[0]=value10
group1[1]=value11

for group in ${groups[@]};do
     sites=${!group}
     echo ${sites[@]}
done



Last echo print only the first value of arrays group0 and group1 not all value.

Any idea?

Thanks in advance and sorry for my not perfect English O:-)

Greetings
Gianluca

Author:  choroba [ Fri Oct 08, 2010 6:23 am ]
Post subject:  Re: Array content as array name

I fear variable indirection cannot be used for arrays. Eval will help you:
Code:
for group in ${groups[@]};do
    eval echo \$"{$group[@]}"
done

Author:  gianlu [ Mon Oct 11, 2010 4:51 am ]
Post subject:  Re: Array content as array name

It works!!

Thank you very much :)

greetings

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com