如何在多重引号里面取到shell变量的值?
双引号是不会屏蔽对变量和某些特殊符号的转义的,而单引号里的所有内容都会原封不动的输出,而单引号里再用单引号将变量引起来,变量就又可以正常的显示,有点像数学里的负负为正。
演示如何取到变量BUILD_NUMBER的值:
num=
while true
do
result_code=`curl -d '{"appName":"offline-index-web","branch":"security-test1-1-20190128","id":"ab432040-b5ca-48ff-946f-ec984748dcae","build_number":'$BUILD_NUMBER'}' http://10.5.25.4:8088/api/v1/job_finish -H "Content-type: application/json" -H "Accept: application/json" -m 10 -w %{http_code} || echo "failed"`
if [[ $result_code == \"ok\"200 ]] ; then
echo "callback successed!"
break
else
echo "callback failed, retry after 10s!"
sleep
fi
num=`expr $num + `
if [[ $num == ]]; then
echo "failed after 5 times"
exit -
break
fi
done