How do I escape backslashes in a sed script embedded in a bash script
问题 I want to edit a file via a sed script in a bash script. I want this to be easy to maintain later; easy to understand and modify. The replacement string looks like: PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\]' In a perfect world, it would like this: sed -i "s/^PS1.*$/PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\]'/g" /etc/skel/.bashrc The problem is that bash and sed are stripping out the \ giving the following result in the file: PS1='[e[1;32m][@h W]$[e[0m]' Obviously single quotes can't be used. A brute