Backtick versus $()

Andres Perera andres.p at zoho.com
Mon Feb 21 03:03:11 UTC 2011


On Sun, Feb 20, 2011 at 1:10 PM, Warren Block <wblock at wonkity.com> wrote:
>
> With backticks, the backreference \1 never seems to be replaced with the
> actual pattern, regardless of search pattern.  Tested on 8-stable and
> 9-current.

this isn't really new and it's not particular to freebsd sh(1)

for i in bash dash mksh; do
echo $i:
$i <<'!'
ra=` printf %s 's%\([?:.%\\]\)%\\\1%g'`
rb=$(printf %s 's%\([?:.%\\]\)%\\\1%g')
printf %s\\n "$ra" "$rb"
!
done

bash:
s%\([?:.%\]\)%\\1%g
s%\([?:.%\\]\)%\\\1%g
dash:
s%\([?:.%\]\)%\\1%g
s%\([?:.%\\]\)%\\\1%g
mksh:
s%\([?:.%\]\)%\\1%g
s%\([?:.%\\]\)%\\\1%g

if you add another backslash to double-slashes in backticks:

for i in bash dash mksh; do echo $i: && $i <<'!'
echo $i:
ra=` printf %s 's%\([?:.%\\\]\)%\\\\\1%g'`
rb=$(printf %s 's%\([?:.%\\]\)%\\\1%g')
printf %s\\n "$ra" "$rb"
!
done

bash:
s%\([?:.%\\]\)%\\\1%g
s%\([?:.%\\]\)%\\\1%g
dash:
s%\([?:.%\\]\)%\\\1%g
s%\([?:.%\\]\)%\\\1%g
mksh:
s%\([?:.%\\]\)%\\\1%g
s%\([?:.%\\]\)%\\\1%g

no, backticks are not supposed to be equivalent


More information about the freebsd-questions mailing list