why does this single quoted string get interpreted when it's inside of a command substitution

扶醉桌前 提交于 2019-12-11 05:43:38

问题


Compare these two lines of shell script:

printf '%s' 's/./\\&/g'                    #1, s/./\\&/g
printf '%s' `printf '%s' 's/./\\&/g'`      #2, s/./\&/g

My question is: why does the single-quoted double backslashes get interpreted as a single backslash for the second line of script?


回答1:


Starting from

printf '%s' `printf '%s' 's/./\\&/g'`

The expression inside backticks returns s/./\\&/g as in the first expression, without single quotes, so you get

printf '%s' s/./\\&/g

The first backslash escapes the second one, so it prints s/./\&/g.



来源:https://stackoverflow.com/questions/37788936/why-does-this-single-quoted-string-get-interpreted-when-its-inside-of-a-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!