shell 组合新的变量名

shell 组合新的变量名

普通变量

name_A=James
name_B=Smith

name=`eval echo '$'"name_$1"`

echo ${name}

 

测试:

#./filename.sh A

#./filename.sh B

 

数组

model_so=dummy.so

R_so_list=(
laaaR lsssR ldddR leeeR lrrrR
)

A_so_list=(
laaaA lsssA ldddA leeeA lrrrA
)

SO_LIST=`eval echo '$'{"$1"_so_list[@]}`

for i in ${SO_LIST[@]}; do

    echo  lib${i:1}.so

done

 

测试:

#./filename.sh A

#./filename.sh R

 

posted @ 2017-11-03 19:18  JamesBlue  阅读(702)  评论(0编辑  收藏  举报