2

I want to substitute a variable SERVICE with a string $service which contains a backslash using sed. I did the following

sed "s/SERVICE/`printf '%q' "${service}"`/g"

Using this I am getting the substituted string as

b_a^c_b_\]Wdd[]X\[X\[W206C?2@,.\\,A@2AW!w6"|

where as I want

b_a^c_b_\]Wdd[]X\[X\[W206C?2@,.\,A@2AW!w6"|

Is there any other way to do it. PS(The string $service has many different special characters)

msd_2
  • 1,117
  • 3
  • 16
  • 22

1 Answers1

3

You might as well not use at all but just like this instead:

while read -r; do
    echo "${REPLY//SERVICE/$service}"
done
gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104