This question already has an answer here:
I have a shell variable which will be used within the replacement string of a sed regex.
Therefore, all characters
\ need to be escaped by a preceeding
I managed to do it for
newvar=`echo "$oldvar" | sed -e 's|&|\\\&|g' -e 's|/|\\\/|g'`
1st question: Is this fine (piping content to sed via echo etc.)?
2nd question: Somehow I cannot get it to work for the backslash. Can you show me how to do it?