I am trying to write a script that generates csv files from mysql. The csv files from mysql is working fine, however, I'm struggling with a way to loop through variables, or treat them as an array to loop through.
Some example variables are below
c1="Client 1"
c1_s1_name=Alpha
c1_s1_id=761967
c1_s2_name=Beta
c1_s2_id=415612
c2="Client 2"
c2_s1_name=XYZ
c2_s1_id=438976
c2_s2_name=ABC
c2_s2_id=982012
c3="Client 3"
c3_s1_name=No-Name
c3_s1_id=347654
c3_s2_name=House
c3_s2_id=109321
I then have some quasi-code that attempts to run a sql script for each client as below but
# loop through all clients
for all_clients in $c1 $c2 $c3
do
# and then loop through for all survey names and all survey ids for each seperate client
for survey_name in $*_name and survey_id in $*_id
do
mysql -h "localhost" -u "root" "$DATABASE" -e "SELECT count(*) FROM $survey_id" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > $all_clients-$survey_name-filename-count.csv
done
done
I'm not sure how to set the script up so that the c1 variables are run as a set and then c2, followed by c3. I'm guessing an array might be what I need but I'm not sure?
I've also come across the answer below but it's for PHP, even though it looks suspiciously like bash...