doubledecker
doubledecker

Reputation: 363

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.

Upvotes: 0

Views: 143

Answers (2)

hjpotter92
hjpotter92

Reputation: 80639

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

Upvotes: 1

user3284427
user3284427

Reputation: 21

try this one :

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

Upvotes: 0

Related Questions