It;s only outputting the final loop body because of the way my loop is set up, the variable var's final result will be the final element in my array. How would I loop through the body and add all of the results of my array to the .sql file?
1 Answer
Try this:
echo "CREATE TABLE $NameOfTable (" > "$NameOfSqlFile.sql"
for i in "${ColumnArray[@]}"
do
echo "$i,"
done >> "$NameOfSqlFile.sql"
echo ")" >> "$NameOfSqlFile.sql"
3 Comments
user3544582
That would create an sql text file for each element in my array. I want one text file to hold the loop results of my array
John Zwinck
@user3544582: I've updated my answer--please check again.
user3544582
Beautiful! If you remove the EOF at the end of where your wrote echo, it works!