LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   inserting special characters into mysql with bash script (https://www.linuxquestions.org/questions/linux-newbie-8/inserting-special-characters-into-mysql-with-bash-script-507660/)

ihopeto 12-05-2006 11:27 AM

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

unSpawn 12-05-2006 12:46 PM

Try
Code:

while read line; do
line=${line//\"/\\\"}
$user=
# etc etc



All times are GMT -5. The time now is 09:12 AM.