sed ERROR

Hi Leute

Kann mir bitte jemand diesen Fehler rerkl�ren?
Ohne Zuweisung gehts und es kommt der modifizierte String raus.
Weise ich es einem String zu kommt dieser Fehler.
Was mache ich da flasch?

0:521:root@pendrive /media/disk/system_setup [0]# STRING=/mnt/new/path
0:522:root@pendrive /media/disk/system_setup [0]# echo ${STRING} | sed 's/\//\\\//g'
\/mnt\/new\/path
0:523:root@pendrive /media/disk/system_setup [0]# var=`echo ${STRING} | sed 's/\//\\\//g'`
sed: -e Ausdruck #1, Zeichen 9: unknown option to `s'
0:524:root@pendrive /media/disk/system_setup [1]# 


Danke :wink:

Hi latenite, you need to write in English here. This works:

var=$(echo ${STRING} | sed -e 's/\//\\\//g')

I do not know why, I thought the `...` and $( ... ) constructs were equivalent, although I much prefer (and always use) the latter. Note that you can also replace the '/' by a different character (e.g. ':'), (so that you do not have to escape the '/'-characters) like this:

var=$(echo "${STRING}" | sed 's:/:\\/:g')

or simply this:

var=${STRING//\//\\/}

---------- Post updated at 03:57 PM ---------- Previous update was at 03:43 PM ----------

If you use backticks then you appear to have to do more escaping:

var=`echo ${STRING} | sed 's/\//\\\\\//g'`

or

var=`echo ${STRING} | sed 's:/:\\\/:g'`

That is limited to two or three shells; it's not POSIX compliant.

$ var=${STRING//\//\\/}
dash: Bad substitution

Indeed. It works in bash, zsh and ksh93.