Append elements of an Array to another Array

In this blog, sharing code of appending elements of one Array to another.

arr=(1 2 3 4) ## Array of 4 Elements
arr_2=(5 10 12 1) ## Another Array of 4 Elements
i=0
len=${#arr_2[@]} ## It gives the length of an Array arr_2
while [ $i -lt $len ]
do
arr+=(${arr_2[i]}) ## Appending elements of arr_2 into array arr.
i=$(( $i + 1))
done
echo ${arr[*]}

Related posts