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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build array using Variable 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi Folks,

I was wondering ... ;-)

I know I can create an Array using

Code:
set -A myarray $(cat filename.txt)

So ... Is it possible to do the same using Variables like that:

Code:
for i in sys1 sys2 sys3;
do
set -A AR$i $(cat /tmp/$i.txt)
done

Using the code from above I Keep getting the error message "This is not an identifier.". And another Problem would be that I have no idea how to reference elements within that Array later on ...

Like this:

Code:
echo ${AR$i[0]}

or

Code:
echo ${AR\$i[0]}

Regards,
Thomas
 
Have a look at the eval builtin.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Not sure if it helps, but is it just as easy to say:
Code:
for i in sys1 sys2 sys3;
do
set -A AR$i $(cat /tmp/$i.txt)
done
to something like:
Code:
for i in sys1 sys2 sys3;
do
AR$i=$(cat /tmp/$i.txt)
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top