I am a new to Bash. I have an array taking input from standard input. I have to concatenate itself twice. Say, I have the following elements in the array:
Namibia
Nauru
Nepal
Netherlands
NewZealand
Nicaragua
Niger
Nigeria
NorthKorea
Norway
Now, The output should be:
Namibia Nauru Nepal Netherlands NewZealand Nicaragua Niger Nigeria NorthKorea Norway Namibia Nauru Nepal Netherlands NewZealand Nicaragua Niger Nigeria NorthKorea Norway
My code is:
countries=()
while read -r country; do
countries+=( "$country" )
done
countries=countries+countries+countries # this is the wrong way, i want to know the right way to do it
echo "${countries[@]}"
Note that, I can print it thrice like the code below, but it is not my motto. I have to concatenate them in the array.
countries=()
while read -r country; do
countries+=( "$country" )
done
echo "${countries[@]} ${countries[@]} ${countries[@]}"
question from:https://stackoverflow.com/questions/31143874/how-to-concatenate-arrays-in-bash