LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 12:27 PM   #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, 01:46 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,543
Blog Entries: 54

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:19 AM
Inserting a special character with the keyboard #2 Schreiberling Linux - General 1 06-11-2006 04:57 PM
bash and filenames with special characters CoolAJ86 Programming 2 03-09-2005 03:50 PM
how to have no interpretation of special characters (ctrl, tab ...) in a script xround Linux - General 1 11-29-2004 08:21 AM
inserting/deleting characters into a text file ananthbv Programming 7 07-14-2004 12:40 AM


All times are GMT -5. The time now is 03:26 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration