1

I've the following variable :

x="envVar"

and 'envVar' is the one of my environment variable's name containing a path (of a folder by instance). So I'd like to do

cd $x 

but it doesn't work. How can I do to use x's value as the environment variable ?

I wasn't able to make it work with "eval".

10

1 Answer 1

2

If you have ksh 93, you can declare x to be a reference to a variable name:

$ ksh --version
  version         sh (AT&T Research) 93u+ 2012-08-01
$ ksh -c '
    envVar=foo
    x=envVar
    nameref x
    echo $x
'
foo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .