Home > OS >  Error : unexpected EOF while looking for matching `''
Error : unexpected EOF while looking for matching `''

Time:04-16

I have created a script to export CSV data to mysql table.

#!/bin/bash

cd /data/NEW

for f in User*
do
        mysql --user="root" --password="user@123" -e "LOAD DATA LOCAL INFILE  '/data/NEW/"$f"' ignore into table new.table2 fields terminated by ',' enclosed by '"' lines terminated by '\n' (table_date, table_name, table_count);"

done

But I am getting following errors. But I could not find where I have messed this.

test.sh: line 6: unexpected EOF while looking for matching `''
test.sh: line 9: syntax error: unexpected end of file

Can someone show me where to improve?

CodePudding user response:

Try escaping double quotes as follows:

#!/bin/bash

cd /data/NEW
for f in User*
do
        mysql --user="root" --password="user@123" -e "LOAD DATA LOCAL INFILE  '/data/NEW/$f' ignore into table new.table2 fields terminated by ',' enclosed by '\"' lines terminated by '\n' (table_date, table_name, table_count);"

done
  • Related