echo "testing:"
PROXY_URL="/proxyurl/"
proxyUrlSedEscaped=`echo "$PROXY_URL" | sed -e 's/[\/&]/\\&/g'`
echo "$PROXY_URL" | sed -e 's/[\/&]/\\&/g'
echo "$proxyUrlSedEscaped"
echo "???"
The above has the following output:
testing:
\/proxyurl\/
&proxyurl&
???
Why is the last echo output different from the previous echo output?
This command works correctly via the command line:
PROXY_URL="/proxyurl/"; echo "$PROXY_URL" | sed -e 's/[\/&]/\\&/g', output: \/proxyurl\/
proxyUrlSedEscaped=$(echo "$PROXY_URL" | sed -e 's/[\\/&]/\\&/g'). And according to tldp.org/LDP/abs/html/commandsub.html: "The $(...) form has superseded backticks for command substitution.".