Operating System - HP-UX
1752584 Members
4361 Online
108788 Solutions
New Discussion юеВ

Re: How to assign varibale in another variable

 
Sanjeev gupta_2
Frequent Advisor

How to assign varibale in another variable

Hi All,

I'm facing one issue in shell script :
I assign some value to a variable ser and now I want to assign some value to another varibale i.e.like adb$ser as below :

$ ser=as
$ abd$ser=4
ksh: adbas=4: not found

but I'm geeting error as shown above, pl. help me to resolev it.
thx in advance
sanjeev gupta
6 REPLIES 6
Steven Schweda
Honored Contributor

Re: How to assign varibale in another variable

bash$ ser=as
bash$ eval abd$ser=4
bash$ echo $abdas
4

"man ", look for "eval".
Sanjeev gupta_2
Frequent Advisor

Re: How to assign varibale in another variable

I'm not able to do it. I'm usinh korn shell and getting same error.
Pl. help me out on it.
sanjev gupta
Laurent Menase
Honored Contributor

Re: How to assign varibale in another variable

with the eval it should work


under ksh I did exactly
# ser=as
# eval abd$ser=4
# echo $abdas
4


if it doesn't work you can try
# set -x
# ser=as
# eval abd$ser=4

It will display the line it is trying to execute before executing it.
Hakki Aydin Ucar
Honored Contributor

Re: How to assign varibale in another variable

it must be worked :

agui02# ksh
agui02# echo $0
ksh
agui02# ser=as
agui02# eval adb$ser=4
agui02# echo adb$ser
adbas

Hakki Aydin Ucar
Honored Contributor

Re: How to assign varibale in another variable

Sorry I missed the last line:

agui02# echo $adbas
4
Steven Schweda
Honored Contributor

Re: How to assign varibale in another variable

> I'm not able to do it.

You're not able to do _what_?

Showing actual commands with their actual
output can be more helpful than vague (or no)
descriptions and interpretations.

You know, like what _every_ answer here did.