Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This KornShell Script (ksh):

envir=Dev
eval "${envir}foo=bar"
echo "$Devfoo"

Output:

bar

But I will not know what value is assigned to envir variable. So I want to do something like this where the output is the same as above:

envir=Dev
eval "${envir}foo=bar"
echo "${${envir}foo}"

Output:

${${envir}foo}: bad substitution
share|improve this question
    
is this ksh88 or ksh93? –  glenn jackman Jul 28 at 16:55
    
Not sure, but I assume ksh88. –  javaPlease42 Jul 28 at 17:45
    
Try ksh --version or what $(which ksh) –  glenn jackman Jul 28 at 17:56
    
--version: 0403-010 A specified flag is not valid for this command. The what $(which ksh) command has a lot of output. Not sure what to look for. –  javaPlease42 Jul 28 at 17:58
    
What would be a better title for this question? –  javaPlease42 Jul 28 at 18:31

1 Answer 1

For ksh93, you have (at least) a couple of choices

  1. associative arrays

    envir=Dev
    foo["$envir"]=bar
    echo "${foo["$envir"]}"
    
  2. namerefs

    nameref var=${envir}foo
    var=bar
    echo "$var"
    

For ksh88, you may be stuck with eval:

envir=Dev
name="${envir}foo"
eval "$name=bar"
eval "echo \$$name"
share|improve this answer
    
I must have ksh88 because only the eval solution worked.Thank You! ksh: Dev: 0403-009 The specified number is not valid for this command. ksh: nameref: not found. –  javaPlease42 Jul 28 at 17:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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