Backtick versus $()

Warren Block wblock at
Sun Feb 20 18:06:16 UTC 2011

$() apparently isn't quite the same as backticks, although sh(1) doesn't 
mention that, or I just missed it.  This script is just supposed to 
escape special characters* in a path/filename:



PSTR=`echo "${DESTDIR}${COMPFILE}" | sed 's%\([?:.%\\]\)%\\\1%g'`
echo ${PSTR}

PSTR=$(echo "${DESTDIR}${COMPFILE}" | sed 's%\([?:.%\\]\)%\\\1%g')

% ./

With backticks, the backreference \1 never seems to be replaced with the 
actual pattern, regardless of search pattern.  Tested on 8-stable and 

*: That's special characters as less(1) -Ps sees them.

More information about the freebsd-questions mailing list