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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.