In a string how to add backslash "\" before apostrophe
Iam creating a shell script that have a variable with apostrophe. Want to add backslash before the variable like "St Antony\'s company" and give this variable in the WHERE condition of a sql query.
My script Var1="St Antony's company" if [[ "$Var1" =~ \' ]] then Var1= `echo $Var1 | sed s/\'/\\\\\'/g` echo $Var1 fi echo -n "SELECT field1, field2 FROM table1 WHERE field3='$VAR'"; but it is not working. Please help me |
Use double quotes around sed command
Code:
sed "s/'/\\\'/g" |
Quote:
|
If using bash you could just do the change in place:
Code:
Var1="St Antony's company" |
All times are GMT -5. The time now is 02:46 PM. |