3

I need to add a text string:

--with-mpm=event \

to httpd.spec on 138th position.

I tried:

sed -i '138i--with-mpm=event \\' /root/rpmbuild/SPECS/httpd.spec

This code runs in bash script of Vagrantfile during bootstrapping virtual machine. However, the script returns error.

When I check httpd.spec, output is a string missing backslash:

--with-mpm=event 

It works okay running it directly in shell of virtual machine though.

How can I fix it with sed?

Thanks!

Emma
  • 27,428
  • 11
  • 44
  • 69
ERemarque
  • 497
  • 3
  • 16

1 Answers1

2

The rule of thumb when dealing with backslashes is keep adding up backslashes until you get the expected result.

In this case, a literal backslash here needs to be coded with four backslashes:

sed -i '138i--with-mpm=event \\\\' /root/rpmbuild/SPECS/httpd.spec
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563