Artificial intelligent assistant

Slash and backslash in sed I want to use `sed` to change a slash into a backslash and a slash, i.e. `/` -> `\/`. But it does not work. Here a small example: #!/bin/bash TEST=/etc/hallo echo $TEST echo $TEST | sed "s/hallo/bello/g" echo $TEST | sed "s/\//\\\//g" The output of the first three lines is as assumed. But the last one does not work. Why? How to correct the last part?

Use single quotes for the expression you used:


sed 's/\//\\\//g'


In double quotes, `\` has a special meaning, so you have to backslash it:


sed "s/\//\\\\\//g"


But it's cleaner to change the delimiter:


sed 's=/=\\/=g'
sed "s=/=\\\/=g"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy be4a80b2f7565348258a72b2183daec1