这一个适用于单行字符串:如何扩展的bash变量中的字符串,并保留换行符
var2="2018"
str="${var1:-hello} world!
Happy $var2 new year $var2"
newstr=()
for cnt in "$str" ;do
echo "$cnt"
[ "${cnt:0:1}" == '$' ] && cnt=${cnt:1} && cnt=${!cnt}
newstr+=($cnt)
done
newstr="${newstr[*]}"
如何保存换行符?
您的输入和预期输出是什么? – Inian
这可能是帮助; http://unix.stackexchange.com/questions/27423/how-to-discover-a-new-line-using-a-for-loop –
您的初始前提是,参数为模板系统奠定了良好的基础,现在故障。 – chepner