Is it the $page_text where you want to escape quotes?
Because there are two types of quotes to escape, you could do it like this:
page_text="${page_text//\'/\'}"
page_text="${page_text//\"/\\\"}"
or page_text=$(GET domain | sed 's/['"'"'"]/\\&/g')
Notice the sed command. MySQL isn't alone in not liking embedded quotes. I had to break up the sed command so that the shell wouldn't balk.
Here I'll add some extra spaces so that it is clearer:
Code:
sed 's/[' "'" '"]/\\/&/g'
Embedding single quotes in a bash string is the tricky part.
example demo:
Code:
jschiwal@hpamd64:~> GET domain
Welcome. This is a "sample" test. Let's see another sentence.
jschiwal@hpamd64:~> GET | sed 's/['"'"'"]/\\&/g'
Welcome. This is a \"sample\" test. Let\'s see another sentence.
Code:
jschiwal@hpamd64:~> page_text="$(GET domain)"
jschiwal@hpamd64:~> page_text="${page_text//\'/\'}"
jschiwal@hpamd64:~> page_text="${page_text//\"/\\\"}"
jschiwal@hpamd64:~> echo $page_text
Welcome. This is a \"sample\" test. Let\'s see another sentence.