Reputation: 8978
I have the following shell script with finds all the files and then should insert the filenames in to the database. The only problem I have is that I keep getting the error:
./testDBScript.sh: line 16: syntax error: unexpected end of file
I am trying to insert in to a mysql database from my script using the following code in a loop like:
for filename in `find . \! -name [*./]`
do
echo "$filename"
insert_statement_for_db="insert into files(filename) VALUES(\"$filename\");"
mysql -h $db_host -u $db_user -D $db_database << finish
$insert_statement_for_db
finish
done
How else could I insert in to the database? As tutorials online lead me to that solution.
Upvotes: 2
Views: 1193
Reputation: 10020
It may be due to missing semicolon after the list of values for
should iterate over. Try replacing the corresponding line with
for filename in `find . \! -name [*./]`;
kev's note on here-documents is also right. You can either change indentation or use the alternative format:
<<-finish
here-document
finish
In this case the final finish
can be preceded by tabs (but spaces still won't work).
Upvotes: 3
Reputation: 161674
The format of here-documents is:
<<finish
here-document
finish
No indentation before finish
.
Upvotes: 3