Register
It is currently Sun Oct 26, 2014 1:00 am

Array content as array name


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Oct 08, 2010 4:02 am   

Joined: Fri Oct 08, 2010 3:42 am
Posts: 2
Location: Milano - Italy
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


Top
 Profile  
 PostPosted: Fri Oct 08, 2010 6:23 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
I fear variable indirection cannot be used for arrays. Eval will help you:
Code:
for group in ${groups[@]};do
    eval echo \$"{$group[@]}"
done


Top
 Profile  
 PostPosted: Mon Oct 11, 2010 4:51 am   

Joined: Fri Oct 08, 2010 3:42 am
Posts: 2
Location: Milano - Italy
It works!!

Thank you very much :)

greetings


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP