我想获取存储在$variable1
:
term 1
term 2
term 3
附加$variable2
,其中包含:
addition
所以,它变成了:
term 1,addition
term 2,addition
term 3,addition
诀窍是它可以使用两者作为变量。我在想,回声,粘贴,awk或sed。它可能是这样的:
while read line $variable1; do echo "$line,$variable2"; done
我和他们一起玩过但是当涉及到变量和引用时,我搞砸了。任何帮助是极大的赞赏。
答案 0 :(得分:1)
使用GNU bash和here string:
while IFS='' read -r line; do echo "$line,$variable2"; done <<< "$variable1"
输出:
term 1,addition term 2,addition term 3,addition