4 ms·
As far as I know, escaping single quotes inside single quotes doesn't work in bash: tiksi@emperor:~$ curl 'http://\'test' > > > >^C tik
by Tiksi 12y ago
As far as I know, escaping single quotes inside single quotes doesn't work in bash:
tiksi@emperor:~$ curl 'http://\'test'
>
>
>
>^C
tiksi@emperor:~$ curl 'http://\'test''
curl: (6) Could not resolve host: \test
tiksi@emperor:~$
Anything inside single quotes is treated literally, so no escapes work.( Unless you're doing $'.stuffhere', but that's a whole other can of worms). The double quotes around single quotes does work though.
- 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 :)