Re: Is there a way to use a variable in a veriable name? (132 Views)
Reply
Honored Contributor
Bill Costigan
Posts: 1,427
Registered: ‎09-19-2000
Message 1 of 4 (132 Views)
Accepted Solution

Is there a way to use a variable in a veriable name?

If I have the following [using ksh]

num_1_num=abc
num_2_num=def
num_3_num=ghi

x=2
Is there some way to do the following?
echo $num_($x)_num

I don't want to use an array because the initial variables are already set

Honored Contributor
OldSchool
Posts: 3,372
Registered: ‎09-09-2004
Message 2 of 4 (132 Views)

Re: Is there a way to use a variable in a veriable name?

n_1_a=abc
n_2_a=def
n_3_a=ghj

x=2
a=n_${x}_a
eval echo \$$a
Honored Contributor
OldSchool
Posts: 3,372
Registered: ‎09-09-2004
Message 3 of 4 (132 Views)

Re: Is there a way to use a variable in a veriable name?

or:
"fsm" 7 lines, 72 characters
n_1_a=abc
n_2_a=def
n_3_a=ghj

x=2
eval echo \${n_${x}_a}

Honored Contributor
Bill Costigan
Posts: 1,427
Registered: ‎09-19-2000
Message 4 of 4 (132 Views)

Re: Is there a way to use a variable in a veriable name?

Thank you oldschool.

That's what I'll do.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.