Env Variable substituion in Sed (-s option)

Folks,
I've been trying to use the ENV variable with slashes(/) in its value inside the sed substitution..

Sed 's/myval/'$MYVAL'/' file1 >> file.tmp

If MYVAL=<sometext>, it works.
if MYVAL=/home/venkat, it doesnt.
***************************
bash-2.05$ export VAL=/home/venkat
bash-2.05$ sed 's/myval/'$VAL'/' file1
sed: command garbled: s/myval//home/venkat/
bash-2.05$
*****************************

I know that we generally escape the / using \, but here the value being substitued during run-time.

Could some1 throw some light on it.

Thx 4 ur time.

--Venkat.

sed doesn't know that. All it ever knows it what it gets as it's arguments no matter how they are prepared.

You may well have to encode your path so each / is prefixed by \ before you pass it to sed.

Thx Portor.
I am prefixing it with \ now.
Please note that need to prefix with 2 slashes.

************************************
bash-2.05$ export VAL=\\/home\\/venkat
bash-2.05$ echo $VAL
\/home\/venkat
bash-2.05$ sed 's/myval/'$VAL'/' file1

**********************************

Or just use a different separator:

bash 3.2.25(1)$ VAL=/home/venkat
bash 3.2.25(1)$ sed "s#myval#$VAL#" <(printf "myval\n")
/home/venkat

Wow..this is another cool feature..I tried it now and works.

Thanks radoulov.
So, then we can use any seperator in Sed?

Sed will treat the character immediately after the 's' as the separator,
don't know if there are any restrictions.