INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Build array using Variable

Build array using Variable

(OP)
Hi Folks,

I was wondering ... winky smile

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

RE: Build array using Variable

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close