I am trying to replace a line in a file with the value of a variable (the variable contains a windows path). Although the variable prints correctly to STDOUT, when used in sed to replace the line of interest, the backslashes disappear.
Any idea how to remedy this? Other ideas welcome.
CODE:
WINPATH=”\\\\hd-place\\stor1\\fold1\\archive\\$VAR1.$Var2\\Viewer”
print this to screen (as it should): \\hd-place\stor1\fold1\archive\$VAR1.$Var2\Viewer
The SED command I’m using is: cat file.xml | sed “3 c\
<\RunFolder>$WINPATH</RunFolder>” (please excuse the slashes inside the XML tags)
This outputs this:
\hd-placestor1fold1archive$VAR1.$Var2Viewer
Where as I want this:
\\hd-place\stor1\fold1\archive\$VAR1.$Var2\Viewer
You need one additional layer of escapes for the backslashes, as
sedalso interprets them after the variable has been expanded.