在Bash中逐行组合两个数组

时间:2017-02-03 12:57:57

标签: arrays bash

我在BASH中有2个数组,我想逐行组合,即

Known

当简单地将一个数组添加到另一个数组时,它就像export class Known { name: string constructor(name: string){ this.name = name; } public checkRev(){ console.log('fired!') } } 一样,我希望此组合的输出为arr1=( 1 2 3 4 ) arr2=( 5 6 7 8 ) (逐行)

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

arr1=( 1 2 3 4 )
arr2=( 5 6 7 8 )

declare -a result

resultIndex=0
for index in ${!arr1[*]}; do
  result[$resultIndex]=${arr1[$index]} 
  let "resultIndex++"
  result[$resultIndex]=${arr2[$index]} 
  let "resultIndex++"
done

echo "${result[@]}"