2

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.

2 Answers 2

3

The format of here-documents is:

<<finish
    here-document
finish

No indentation before finish.

Sign up to request clarification or add additional context in comments.

Comments

3

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).

1 Comment

kev's answer didn't work for me, but using >>-finish worked. Thanks.

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.