Find the answer to your Linux question:
Results 1 to 3 of 3
I need to substitute the array name by selecting it dynamically. set -A color red blue green set -A mobile nokia se moto m=color k=mobile eval echo \${${m}[*]} I got ...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    3

    Help with Array name substitution

    I need to substitute the array name by selecting it dynamically.

    set -A color red blue green
    set -A mobile nokia se moto
    m=color
    k=mobile

    eval echo \${${m}[*]}

    I got this above logic by searching in this forum.

    But i need to get this in the for loop. I'm trying to do something like below

    for i in `eval echo \${${m}[*]}` ; do
    print $i
    done

    but this gives an error.

    I need to process all elements of an array but the array to select depends on user input.

    Can you please help?

    Thank you.

  2. #2
    Just Joined!
    Join Date
    Apr 2009
    Posts
    3

    Still need help!!

    Can somebody please help?

    If there is no solution to the above problem (pls let me know if there is a very obvious solution), Can you please tell me how i can assign that to a variable and then do the for loop based on it.

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Posts
    3

    Got a way to assign it to a variable

    eval var=\${${m}[*]}

    If somebody knows a better solution, please let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...