I am trying to create a script that combines 2 arrays:
#!/bin/bash
read -a unix #(a c e g)
read -a test #(b d f)
#now I want to merge ${unix[@]} with ${test[@]}, one after another such that the result would be: (abcdefg) #I've tried quite a few options and can't seem to make it work
#!/bin/bash
unix=( a c e g )
test=( b d f )
printf "%s\n" ${unix[@]} >/tmp/1
printf "%s\n" ${test[@]} >/tmp/2
result=$( paste /tmp/1 /tmp/2 )
echo ${result[@]}
rm /tmp/1 /tmp/2
or shorter:
#!/bin/bash
unix=( a c e g )
test=( b d f )
result=$( paste <( printf "%s\n" ${unix[@]} ) <(printf "%s\n" ${test[@]}) )
echo ${result[@]}