i am trying to replace the quotes in a string in my bash script. i have a variable that will be placed in a mysql query that may possibly have a single quote in it. i want to replace any ' with \' so i can escape any quote and not screw up my query.
i tried this as a test but it doesn't work:
text="bobby's test"
echo ${text/#'/\\\'}
what am i doing wrong or is there even a better way to do this that i havent thought of? i prefer to not have to use sed or anything as well.
echo "${text//\'/\'}"
Make sure you use the double quotes on the outside, or you are going to need more escaping (ugh).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With