Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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}

Highlighted
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.