急,shell字符串转义问题,请高手帮忙,谢谢。
定义字符串:
ttt="
MT huihui" //firstofper1字符串中有空格导致下面的sub函数中"'$ttt'"语法错误,该怎么改,谢谢。
qqq="happy"
Fomatinfo="name:%s,ip:%s,port:%s."
firstofper0=`echo "$Fomatinfo" | awk '{sub(/%s/,"'$qqq'",$0); print}'`
echo $firstofper0
输出:name:happy,ip:%s,port:%s."
firstofper1=`echo "$Fomatinfo" | awk '{sub(/%s/,"'$ttt'",$0); print}'`
echo $firstofper1
语法错误
------解决方案--------------------echo $Fomatinfo
------解决方案-------------------- sed "s/%s/$ttt/"
------解决方案--------------------firstofper1=`echo "$Fomatinfo"
------解决方案-------------------- awk -v awk_var="$ttt" '{sub(/%s/,awk_var,$0); print}'