0

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
  • please include your code as text, not an image. Commented Dec 14, 2015 at 13:59

1 Answer 1

1

Try this:

echo "CREATE TABLE $NameOfTable (" > "$NameOfSqlFile.sql"
for i in "${ColumnArray[@]}"
do
echo "$i,"
done >> "$NameOfSqlFile.sql"
echo ")" >> "$NameOfSqlFile.sql"
Sign up to request clarification or add additional context in comments.

3 Comments

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
@user3544582: I've updated my answer--please check again.
Beautiful! If you remove the EOF at the end of where your wrote echo, it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.