0

How can escape the literal string #!/bin/bash in a sed expression? Curently I have a command in a bash script of the form

sed 's/Parametersettings:/HERE/g' outpad1 > outpad2

I would like the escaped replacement to go where HERE is written in the above.

I have tried all sorts of / \ and $variables with no luck so far.

2
$ echo 'Parametersettings:' | sed 's/Parametersettings:/#!\/bin\/bash/g'
#!/bin/bash

or use a different delimiter, avoiding the need to escape the / characters:

$ echo 'Parametersettings:' | sed 's%Parametersettings:%#!/bin/bash%g'
#!/bin/bash
2

By quoting your string with single quotes ("''"), you PREVENT interpolation by the shell. Use double quotes ("") and the shell will substitute variables, etc.

sed "s/Parametersettings:/$HERE/g" outpad1 > outpad2

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.