title: Dynamic variable names for an array in bash
body: <p>I have an array called "loop".</p>
  
  <p>For each element in "loop" I want to create an array whose name contains the text of the current element.</p>
  
  <p>I then want to loop through each new array and print every element from each array.</p>
  
  <hr>
  
  <p><a href="https://stackoverflow.com/questions/16553089/dynamic-variable-names-in-bash">This post</a> seems to have a good solution for variables but I do not know how to adapt it to work for arrays.</p>
  
  <hr>
  
  <p><strong>My Script</strong></p>
  
  <pre><code>#!/bin/bash
  loop=(
  first
  second
  third
  )
  
  for word in "${loop[@]}"    
  do
          declare "${word}_holder=( hello world )"
          var="${word}_holder"
          echo "$var"
          for i in "${!var}[@]"
          do
                  echo "$i"
          done
  done
  </code></pre>
  
  <hr>
  
  <p><strong>Current output</strong></p>
  
  <pre><code>first_holder
  ( hello world )[@]
  second_holder
  ( hello world )[@]
  third_holder
  ( hello world )[@]
  </code></pre>
  
  <p><strong>Desired Output</strong></p>
  
  <pre><code>first_holder
  hello
  world
  second_holder
  hello
  world
  third_holder
  hello
  world
  </code></pre>