user3544582
user3544582

Reputation: 17

BASH - using a for loop to loop over an array and create a file from the loop body

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?

Upvotes: 0

Views: 59

Answers (1)

John Zwinck
John Zwinck

Reputation: 249133

Try this:

echo "CREATE TABLE $NameOfTable (" > "$NameOfSqlFile.sql"
for i in "${ColumnArray[@]}"
do
echo "$i,"
done >> "$NameOfSqlFile.sql"
echo ")" >> "$NameOfSqlFile.sql"

Upvotes: 1

Related Questions