From owner-freebsd-questions@FreeBSD.ORG Sun Feb 20 18:06:16 2011 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 86602106564A for ; Sun, 20 Feb 2011 18:06:16 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: from wonkity.com (wonkity.com [67.158.26.137]) by mx1.freebsd.org (Postfix) with ESMTP id 3934A8FC20 for ; Sun, 20 Feb 2011 18:06:15 +0000 (UTC) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.14.4/8.14.4) with ESMTP id p1KHelBr056914 for ; Sun, 20 Feb 2011 10:40:47 -0700 (MST) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.14.4/8.14.4/Submit) with ESMTP id p1KHelf1056911 for ; Sun, 20 Feb 2011 10:40:47 -0700 (MST) (envelope-from wblock@wonkity.com) Date: Sun, 20 Feb 2011 10:40:47 -0700 (MST) From: Warren Block To: questions@freebsd.org Message-ID: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.6 (wonkity.com [127.0.0.1]); Sun, 20 Feb 2011 10:40:48 -0700 (MST) Cc: Subject: Backtick versus $() X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Feb 2011 18:06:16 -0000 $() 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: #!/bin/sh DESTDIR="./" COMPFILE=".cshrc" PSTR=`echo "${DESTDIR}${COMPFILE}" | sed 's%\([?:.%\\]\)%\\\1%g'` echo ${PSTR} PSTR=$(echo "${DESTDIR}${COMPFILE}" | sed 's%\([?:.%\\]\)%\\\1%g') % ./test.sh \1/\1cshrc \./\.cshrc 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. *: That's special characters as less(1) -Ps sees them.