inserting special characters into mysql with bash script
I want to insert a string into a mysql table
I am using bash script as follows:
$line --- could contain any and all charcters including ' and ". It is read from another process and piped to this process.
**********************
while read line
do
$user=yrname
$password=yrpassword
mysql -hlocalhost -u$user -p$password -Ddatabase -Be "insert into raw values(\"$line\")"
done
****************
When the string $line has special characters ('and") in it I get errors in mysql insert. I know that I may have to insert the \ in front of these characters...what is a fast and easy way to change the line to put the \ in front of these specail characters. Or can i do something with redefining the string so it will go directly into the table?
Thanks
|