简体   繁体   中英

Escaping quotes in echo for mysql input

I am preparing data to update product descriptions into MySQL database from a CSV file. Sometimes I have data with Single and double quotes. However I'm facing trouble to input data when data have single quotes or double quotes. For Example

sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file

echo -n '\"QB 99307 THUG LIL' BIG TIME BOX CALL\", \"'

is giving an error.

I tried escaping ' with \\' after LIL, but it didn't worked. any help is appreciated.

Try the following:

echo -n "\"QB 99307 THUG LIL' BIG TIME BOX CALL\""

Based on the comment , use this:

system("echo -n \"\\\"QB 99307 THUG LIL' BIG TIME BOX CALL\\\", \\\"\" >> " . FILE_NAME);

试试这个:

`echo -n "QB 99307 THUG LIL' BIG TIME BOX CALL " >> FILE_NAME`;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM