UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old March 2nd, 2005, 07:19 AM
thong_yw thong_yw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 thong_yw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 57 sec
Reputation Power: 0
Scripting - Nested Arrays

I am having some problems trying to access nested arrays. I am using the Bash shell. Let's say I create 2 arrays and wish to put these two arrays into another array. e.g

Code:
reptile=("crocodile" "big lizard" "dinosaur")
bird=("flamingo" "big bird" "emu")
animals=(reptile bird)


I can access the values of the animals array by
Code:
${animals[0]} #gives me reptile


I would like to be able to obtain the values in the reptile array through the animals array. I would like to be able to do something like

Code:
tempbird=${animals[1]}
for everybird in $tempbird
.....
.....
....


the last bit of code above does not work. Could someone be so kind and to please help me out? thx in advance

Reply With Quote
  #2  
Old March 2nd, 2005, 12:13 PM
bingotailspin's Avatar
bingotailspin bingotailspin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 115 bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 52 m 45 sec
Reputation Power: 7
I fairly sure this is not supported in bash. You could use python (www.python.org).

Reply With Quote
  #3  
Old March 3rd, 2005, 08:38 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by bingotailspin
I fairly sure this is not supported in bash. You could use python (www.python.org).



You could try something like

:
reptile=("crocodile" "big lizard" "dinosaur")
bird=("flamingo" "big bird" "emu")
animals=( $(echo ${reptile[@]}) $(echo ${bird[@]}) )
echo ${reptile[@]}
echo ${bird[@]}
echo ${animals[@]}

but it is perhaps not exactly what you want. And you get more array variables, because of spaces in "big bird" etc.

I would prefer perl.

Regards

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Scripting - Nested Arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway