4 ms·
> escaping single quotes inside single quotes That's why you have to escape single quotes with '\'' rather than just \' As I said, you first have to te
by vog 12y ago
> escaping single quotes inside single quotes
That's why you have to escape single quotes with
'\''
rather than just
\'
As I said, you first have to terminate the single-quoted string, then add the single quote, then start a new single-quoted string.
In your example, my variant (1) leads to:
curl 'http://'\''test'
And my variant (2) leads to:
curl 'http://'"'"'test'
- Tiksi 12y agoAh, I misread your first post as meaning '...\'...' instead of literally '\''. I've always used the '"'"' method, or "$(sed -r 's/([allthespecialchars])/\\\1/g')" , but '\'' is much cleaner. I have found the terminate and escape quite useful for color codes though 'string'\e[31m'red'"$var"'morestring', not sure how I never thought to use it for '\'', but thats getting added to my toolbox :)