[olug] sed issues inside of a script

John Hobbs john at velvetcache.org
Tue Nov 13 06:53:15 UTC 2007


First off, hello to the olug mailing list, this is my first time posting.

My problem lies with (I believe) sed.  I'm trying to escape a path
with sed and store that in a variable and it isn't working with `` but
it is with $().

Here's my debugging demo script:

#!/bin/sh

THEPATH='/home/jmhobbs/Desktop'
echo $THEPATH
echo $THEPATH | sed 's/\//\\\//g'
# Won't work
ESCAPEDPATH=`echo $THEPATH | sed 's/\//\\\//g' `
echo $ESCAPEDPATH
# Will work
ESCAPEDPATH=$( echo $THEPATH | sed 's/\//\\\//g' )
echo $ESCAPEDPATH

The output to that is:

$ ./example.sh
/home/jmhobbs/Desktop
\/home\/jmhobbs\/Desktop
sed: -e expression #1, char 9: unknown option to `s'

\/home\/jmhobbs\/Desktop
$

Just curious if anyone knows why that would happen.  Am I missing
something, I thought `` and $() were equivalent.

Thanks in advance for your thoughts!

- John Hobbs



More information about the OLUG mailing list