Possible Duplicate:
sed, foward slash in quotes
In my bash script I have a path string, which I should use in sed
pattern.
SRC_PATH="$PWD"
sed "s/<SRC_PATH>/$SRC_PATH/g" template.sh > replaced.sh
How can I escape the $SRC_PATH
string so it would be safely accepted by sed as a literal replacement?
You need not escape it. Just use other delimiter:
But you must be sure that SRC_PATH contains no
@
(or other symbol if you choose it).Use
s%$OLDPATH%$NEWPATH%
. You can choose your delimiter. If%
is too dangerous, consider Control-A instead.