This function works, but I am thinking there must be a more elegant way to convert all '/' to '\/' (so that I can subsequently feed it into sed using the standard '/' for substitute):
escapeslash() {
val="$1"
fixed=""
while [ 1 ]; do
start=${val%%/*}
remainder=${val#*/}
if [ "${remainder}" = "${val}" ]; then
fixed="${fixed}${start}"
break;
fi
fixed="${fixed}${start}\/"
val="${remainder}"
done
echo "${fixed}"
}