p=0
array="host_01"
HostProjects[$p]="project_01"
AvgCr=1569.22
eval "${array}_${HostProjects[$p]}=$AvgCr"
echo "Host Credit is ${host_01_project_01}"
给我1569.22
但是我怎么能从中得到结果1569.22
printf '%s\n' "${array}_${HostProjects[$p]}"
or even from:
echo "${array}_${HostProjects[$p]}"
哪个给了我host_01_project_01
我尝试了几种方法,但是最终出现语法错误。 谢谢。
答案 0 :(得分:1)
如果您使用的是Bash,则间接参数扩展是您的朋友:
varname="${array}_${HostProjects[$p]}"
echo "The value you want is ${!varname}"