I am trying to pull info from multiple arrays and then echo it out. Unfortunately, I am having some trouble and I am almost positive it is something wrong with my for loop structure.
Lets assume:
array1= 1, 2, 3
array2= toronto, new york, paris
The code that I currently have:
for element in "${array1[@]}" "${array2[@]}"
do
echo ""$element" "element""
done
The output looks something like this:
1 1
2 2
3 3
toronto toronto
new york new york
paris paris
Now this obviously doesn't work because it outputs the same thing twice in each array. So, I tried to use a for loop within a for loop but then I have multiples.
How would I setup the for loop so my output looks like this:
1 toronto
2 new york
3 paris
array2= toronto, new york, parisis not valid at all if you want to define an array.0to"${#array1}"(or"${#array1}"depending on which is longer and what behaviour you want if they don't have the same length).for element in "${array1[@]}" "${array2[@]}"), I was about to attempt something silly (printf '%s\n' "${array1[@]}" "${array2[@]}" | while read....gross). So thanks!