[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: shell script: can it be done?



On 2001-07-19, Emiel Metselaar wrote:

>I wan't to make variable variablenames so
>can a script which looks like:
>
><script>
>#!/bin/sh
>VAR1="a1 a2 a3"
>a1="1 2 3"
>a2="4 5 6"
>a3="10 9 8"
>
>for X in $VAR1; do
>    for Y in $X; do
>        v = ${$Y}
>        echo $Y $v
>    done
>done
></script>
>
>produce results like this:
>a1 1
>a1 2
>a1 3
>a2 4
>a2 5
>a2 6
>a3 10
>a3 9
>a3 8
>
>thanks
>
>emiel

#!/bin/sh
VAR1="A1 A2 A3"
A1="1 2 3"
A2="4 5 6"
A3="10 9 8"

for X in $VAR1; do
  for Y in $X; do
    eval Z=\$\{$Y\}
    for N in $Z; do
      echo $Y $N
    done
  done
done






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]