在bash中连接包含多行的变量

时间:2014-11-08 10:00:15

标签: bash merge echo

鉴于echo "$varA"

Astringline1
Astringline2
Astringline3

echo "$varB"

Bstringline1
Bstringline2
Bstringline3

我想获得:

Astringline1,Bstringline1
Astringline2,Bstringline2
Astringline3,Bstringline3

echo "$varA,$varB"产生:

Astringline1
Astringline2
Astringline3,Bstringline1
Bstringline2
Bstringline3

1 个答案:

答案 0 :(得分:3)

您可以使用paste命令:

varA=$'Astringline1\nAstringline2\nAstringline3'
varB=$'Bstringline1\nBstringline2\nBstringline3'
paste -d, <(echo "$varA") <(echo "$varB")

输出

Astringline1,Bstringline1
Astringline2,Bstringline2
Astringline3,Bstringline3