|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
I fairly sure this is not supported in bash. You could use python (www.python.org).
|
|
#3
|
|||
|
|||
|
Quote:
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Scripting - Nested Arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|