2013年10月10日星期四

shell variable nested

I shell rookie , Great God to ask you a question:
currently defines three variables
typeset aaset = "aa"
typeset bbset = "bb"
typeset ccset = "cc"

There is now a type variable, its value may be aa, bb or cc.
ask how can echo print time by type to select print in front of that three variables ?
with echo $ {$ {type} set} like this is not acceptable.
------ Solution ---------------------------------------- ----

    
print ..          
because I do not know if the problem is ksh , echo out of the aaset, rather than 120 .   
  
seemingly  
ksh To nameref
nameref varname=${type}"set"
echo ${varname}

------ For reference only ----------------------------------- ----
$ aaset=120
$ type=aa
$ varname=${type}set
$ echo ${!varname}


The result is 120 , promised aaset, varname The variable content is the aaset
------ For reference only --------------------- ------------------


print ..
------ For reference only ------------------------------- --------

  
print ..  
because I do not know if the problem is ksh , echo out of the aaset, rather than 120 .

seemingly
------ For reference only --------------------------------- ------
aaset="111"
bbset="222"
ccset="333"
type="bb"
eval echo \$${type}set

------ For reference only -------------------------- -------------

      
      
print ..                
because I do not know if the problem is ksh , echo out of the aaset, rather than 120 .     
    
seemingly          
ksh To nameref   
  
nameref varname=${type}"set"
echo ${varname}
 

could work, thank you very much !

没有评论:

发表评论