I've been searching around for a solution to my problem, being that I have a bash script recursively inputting data into a MySQL database.
Sometimes, the string I want to input contains single quote marks, and this is where my coding becomes stuck.
I want to run a sed or a tr filter over the string before I send it to my SQL processing, and use it to change single quotes to an escape character followed by the same quote, e.g. from '
to \'
.
I have tried the following off other suggestions but the output remains unaltered:
string="Karl's Oil Lamp"
find="'"
replace="\\\'"
echo $string | sed -r 's/$find/$replace/g'
I can see that my string remains unchanged with the output being Karl's Oil Lamp
. I have similar luck when using tr though that may not be the solution I need anyway.
Any kind suggestions? Running Ubuntu 16.04.2 LTS.