2016-05-29 78 views
-2

我有像下面两个变量:如何在Linux/unix中使用管道追加两个变量?

A = 10 20 30 40
B = 1000 2000 3000 4000
我所需要的期望的输出象下面这样:

10 | 1000
20 | 2000
30 | 3000
40 | 4000

我该如何做到这一点?

+0

请看看[编辑的帮助(http://stackoverflow.com/editing-help)。 – Cyrus

+0

你能显示一些代码吗?像你的变数一样;他们是'bash'变量吗? – totoro

回答

0
a1=($a) # if a & b are already arrays, you don't need this step 
b1=($b) # directly go to the for loop. use a,b instead of a1,b1 
for((i=0;i<${#b1[@]};i++)) 
do 
echo "${a1[$i]}|${b1[$i]}" 
done 

应该这样做。

输出

10|1000 
20|2000 
30|3000 
40|4000