1

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?

pdg
  • 103
  • 8

1 Answers1

2

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.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
WilQu
  • 7,131
  • 6
  • 30
  • 38