Getting value of variable whose name is stored in another variable

Unix OS : Linux 2.6x
Shell type : Korn
I am stuck in weird problem .
In my shell script I am setting an environment variable using the following command :

EMP="KUMARJIT"; export EMP

In the following sections of the script , what I did is :
I created and initialized a new shell variable "type" using the following command:

type="EMP"

As because the VALUE OF A SHELL VARIABLE(type) IS THE NAME OF ONE THE ENVIRONMENT VARIABLE(EMP) ,
how can I get the value of variable "EMP" using the shell variable "type" ?

Thanks
Kumarjit.

try this....:b:

type=${EMP}

It's not exactly obvious what you want, but...

$ eval echo \$$type
KUMARJIT

PS: Linux 2.6 is not an operating system, Unix or otherwise!

Were it bash, you could use its "variable indirection":

echo ${!type}
KUMARJIT

In ksh, you could use the ill reputed eval :

eval echo \$$type
KUMARJIT

@Scot and Rudic : Thanks guys for your WONDER replies . It clicked great time .

regards
Kumarjit.

The Korn shell that comes with your OS is ksh93. It should be able to do this:

EMP=KUMARJIT
nameref type=EMP
echo "$type"
KUMARJIT
1 Like