Reputation: 47
In a shell script I would like to quote this string of special characters \'%"\"'\
How do I escape the quotes/backslashes inside the string ?
Upvotes: 1
Views: 809
Reputation: 74635
If you use single quotes around the whole string, then the only thing you need to worry about is replacing every '
with '"'"'
:
$ string='\'"'"'%"\"'"'"'\'
$ echo "$string"
\'%"\"'\
This means:
'
close the previous single-quoted string"'"
a new double-quoted string, containing a single quote'
open a new single-quoted stringThe shell concatenates adjacent strings, so you get a single quote where you want it. You can replace the middle part by \'
but personally I think that's more confusing!
Upvotes: 2