Variable substitution in sed with pathname

red_valsen_at_yahoo.com
Date: 01/14/05


Date: 14 Jan 2005 08:34:27 -0800

How do I do a simple variable substitution in sed with a value that is
a pathname ie includes slashes?

This fails in ksh and bash:

VPATH=/foo/bar
sed -e "s/EXECPATH=.*/EXECPATH=${VPATH}/"<configfile >tmpconfigfile

with error message (in bash):

sed: -e expression #1, char ##: Unknown option to `s'

-- where ## is a column number. The failure occurs whether 1)the
literal for VPATH is quoted with single/double quotes 2) whether
${VPATH} is quoted with escaped single/double quotes. The statment
cannot be enclosed in single quotes since this would entirely prevent
the substitution. The only way to make it work is to modify the
literal variable by escaping the slashes -- which is unacceptable since
this fouls other uses of the variable.



Relevant Pages