title: Creating Arrays From Unknown Number of External Lists
body: <p>this is another question related to importing values from a text file (similar to one of my previous ones), but with added complexity (the more I learn about bash scripting the more challenging it becomes)</p>
  
  <p>The goal: to create an array of Day_.... on each outer loop iteration. I'm trying to do this assuming no knowledge of how many Day_... lists exist in the *.txt file. </p>
  
  <p>The issue: At the moment my inner loop only iterates once (should iterate as the number of elements on <code>Monday</code>. And, also, I'm using <code>my_sub_dom=$( sed 's/=.*//' weekly.txt )</code> to get the number of lists/arrays in weekly.txt and then filter the ones that contain <code>Day</code>.</p>
  
  <p>Bash script:</p>
  
  <pre><code>#!/bin/bash
  
  source weekly.txt
  
  declare -a my_sub_dom
  day=( ${Monday[*]} )
  my_sub_dom=$( sed 's/=.*//' weekly.txt ) # to construct a list of the number of of  lists in the text file
  #echo "${my_sub_dom}"
  counter=0
  main_counter=0
  for i in "${day[@]}"
  do
      let main_counter=main_counter+1
      for j in "${my_sub_dom[@]}"
      do
      #       echo "$j"
              if grep -q "Day" "${my_sub_dom}"
              then
                      echo "$j"
                      sub_array_name="${my_sub_dom[counter]}" # storing the list name
                      sub_array_content=( ${sub_array_name[*]} )
                      echo "${sub_array_content}"
              else
                      echo "no"
              fi
              let counter=counter+1
      done
      echo "$counter"
      counter=0
  </code></pre>
  
  <p>done
  echo "$main_counter"</p>
  
  <p>Text file format:    </p>
  
  <pre><code>Day_Mon=( "google" "yahoo" "amazon" )
  Day_Tu=( "cnn" "msnbc" "google" )
  Day_Wed=( "nytimes" "fidelity" "stackoverflow" )
  Monday= ( "one" "two" "three" )
  ....
  </code></pre>
  
  <p>Script output:</p>
  
  <pre><code>grep: Day_Mon
  Day_Tu
  Day_Wed
  Monday: No such file or directory
  no
  1
  grep: Day_Mon
  Day_Tu
  Day_Wed
  Monday: No such file or directory
  no
  1
  grep: Day_Mon
  Day_Tu
  Day_Wed
  Monday: No such file or directory
  no
  1
  3
  </code></pre>
  
  <p>Please let me know if you'd like any other information.... And I really appreciate any input in this matter, I've been trying this for a couple of days now. </p>
  
  <p>Thank you</p>