LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-05-2006, 11:27 AM   #1
ihopeto
LQ Newbie
 
Registered: Jan 2006
Posts: 19

Rep: Reputation: 0
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
 
Old 12-05-2006, 12:46 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Try
Code:
while read line; do
line=${line//\"/\\\"}
$user=
# etc etc
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: cannot enter special-named dir from script Roger Krowiak Programming 3 08-24-2006 06:19 AM
Inserting a special character with the keyboard #2 Schreiberling Linux - General 1 06-11-2006 03:57 PM
bash and filenames with special characters CoolAJ86 Programming 2 03-09-2005 02:50 PM
how to have no interpretation of special characters (ctrl, tab ...) in a script xround Linux - General 1 11-29-2004 07:21 AM
inserting/deleting characters into a text file ananthbv Programming 7 07-13-2004 11:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration