Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Array names

Status
Not open for further replies.

columb

IS-IT--Management
Feb 5, 2004
1,231
EU
I have a number of arrays set up using
Code:
#!/bin/ksh
set -A arr1 data11 data12 data13 data14
set -A arr2 data21 data22 data23 data24
set -A arr3 data31 data32 data33 date34
....
What I want to do is to select the array using a variable. Something that might look like
Code:
result=${arr${number}}[$index]
I've been playing around with eval but can't seem to get it right. Any pointers please?

Ceci n'est pas une signature
Columb Healy
 
How about something like this

#!/bin/ksh
set -A arr1 data11 data12 data13 data14
set -A arr2 data21 data22 data23 data24
set -A arr3 data31 data32 data33 date34

integer i=1
while (( i <= 3 ))
do
eval echo \${arr$i[*]}
(( i = i + 1 ))
done
 
What about this ?
Code:
eval result=\${arr$number[$index]}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks guys - I would probably have got there eventually but you've saved me hours (days?) of trial and error.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top