Operating System - Linux
1753788 Members
7386 Online
108799 Solutions
New Discussion юеВ

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

 
SOLVED
Go to solution
Bill Costigan
Honored Contributor

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

3 REPLIES 3
OldSchool
Honored Contributor
Solution

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
OldSchool
Honored Contributor

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}

Bill Costigan
Honored Contributor

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

Thank you oldschool.

That's what I'll do.