Backtick versus $()

Warren Block wblock at wonkity.com
Mon Feb 21 02:37:38 UTC 2011


Dropped the last line of the script.  Also lined up the seds to show the 
regex is the same in both.

#!/bin/sh

DESTDIR="./"
COMPFILE=".cshrc"

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

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

Also, the difference is in escapes; two more backslashes added to the 
backtick version make it work:

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

Still: aren't backticks and $() supposed to be equivalent?


More information about the freebsd-questions mailing list