sed substitute / for \ : error "Function can not be parsed"

Hello all,

I have a weird issue when trying to substitute the slashes into backslashes.

If I execute this on the command-line (bash / ksh) I get the path correctly translated with backslashes instead of slashes.

>  echo $PWD | sed 's/\//\\/g'

However, when I put this in my script to have the output in the variable "newpwd" I get the error "sed: 0602-404 Function s/\//\\/g can not be parsed."

Code:

----------------------------------------------
#! /bin/sh
newpwd=`echo $PWD | sed -e 's/\//\\/g'`
echo $newpwd
----------------------------------------------

Does anyone know what's going on here?
How can I then translate the / into \ ?

Many thanks in advance!

Tom

try this,

not tested

abc=`echo $PWD | sed 's/\//\\\\/g'`
echo $abc

For more legibility, you can use the character of your choice as sed substitution delimiter instead of /
Try this :

#! /bin/sh
newpwd=`echo $PWD | sed -e 's_/_\\_g'`
echo $newpwd

Jean-Pierre.

Thanks guys!

matrixmadhan's solution worked nicely :slight_smile: