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

forlibraryin`ls${TN3RD_SRC_TOP}/`doif["${TN3RD_$(echo${library}|tr'[a-z]''[A-Z]')_SUP... 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
展开
 我来答
良玉小帝
2017-11-17 · 个人日常精心汇总合集
良玉小帝
采纳数:5925 获赞数:9451

向TA提问 私信TA
展开全部
不能这样写 "${TN3RD_$(echo ${library} | tr '[a-z]' '[A-Z]')_SUPPORT}"
直接写:
if [ "$library" == "zlib" ];then

echo "${library} is included"
fi
追问
${TN3RD_SRC_TOP}目录下有很多文件夹, 我要做的是通配, 不是具体的zlib
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式