问题
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