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 展开
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 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询