Skip to content
Advertisement

Replacement of PS1 variable in .bashrc using Sed or Perl

I am trying to replace a line in file and am running in to issues.

Original File:

JavaScript

Command I am running:

JavaScript

Error message:

JavaScript

I also tried sed:

JavaScript

Result with Sed:

JavaScript

Expected Result File:

JavaScript

End Result

This doesn’t have much to do with the question except to show folks what the PS1 will look like when working properly

enter image description here

Advertisement

Answer

For sed, you have to escape each backslash with another backslash for them to be treated literally.

The s command additionally requires you to escape the delimiter and &, so it’s easier to use the c command, so that doubling backslashes is the only requirement:

JavaScript

If file.txt contains:

JavaScript

then after running this command, it will contain:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement