shell - Ksh nested substitution -


i have following configuration file:

export profile_active=0   export profile_scsadp01[0]="0 84" export profile_scsadp04[0]="85 170" export profile_scsadp05[0]="171 255"  export profile_scsadp01[1]="-1 -1" export profile_scsadp04[1]="85 170|0 42" export profile_scsadp05[1]="171 255|43 84" 

i access these variable using substitution in ksh script:

i can access each variable using syntax, working:

result=${profile_scsadp01[${profile_active}]}

however need bold part variable, not fixed.

i have tired syntax:

temp="profile_scsadp01" result=${$temp[${profile_active}]} 

however bad substituion error. have tried workaround, cannot find working,

ksh has typeset -n command (see here), think preferred solution:

typeset -n tmp="profile_scsadp01" result=${tmp[${profile_active}]} 

you useeval (be careful) this:

tmp="profile_scsadp01" result=$(eval echo \${$tmp[${profile_active}]}) 

eval parses command once before run, after eval completes, resulting command looks this:

result=$(echo ${profile_scsadp01[0]}) 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -