Linux shell: 变量与字符串拼接出新变量到if语句

for library in `ls ${TN3RD_SRC_TOP}/`
do
if [ "${TN3RD_$(echo ${library} | tr '[a-z]' '[A-Z]')_SUPPORT}" == "y" ];then
echo "${library} is included"
fi
done

希望的结果: 如果在${TN3RD_SRC_TOP} 目录下含有zlib目录, 则if语句会转换成:
if [ "${TN3RD_ZLIB_SUPPORT}" == "y" ];then
fi

但实际运行后报错:
./tv2next3rd/build/build-3rd.sh: line 57: ${TN3RD_$(echo ${library} | tr '[a-z]' '[A-Z]')_SUPPORT}: bad substitution
问题解决了:
for library in `ls ${TN3RD_SRC_TOP}/`
do
TN3RD_LIBRARY_ENV="TN3RD_$(echo ${library} | tr '[a-z]' '[A-Z]')_SUPPORT"
if [ "$(eval echo '$'${TN3RD_LIBRARY_ENV})" == "y" ];then
TN3RD_LIBRARIES="${TN3RD_LIBRARIES} ${library}"
fi
done

不能这样写 "${TN3RD_$(echo ${library} | tr '[a-z]' '[A-Z]')_SUPPORT}"
直接写:
if [ "$library" == "zlib" ];then

echo "${library} is included"
fi追问

${TN3RD_SRC_TOP}目录下有很多文件夹, 我要做的是通配, 不是具体的zlib

温馨提示:答案为网友推荐,仅供参考
相似回答