From owner-freebsd-questions@FreeBSD.ORG Sun Feb 20 18:11:47 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 56FEA106564A for ; Sun, 20 Feb 2011 18:11:47 +0000 (UTC) (envelope-from demelier.david@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id D59AA8FC13 for ; Sun, 20 Feb 2011 18:11:46 +0000 (UTC) Received: by bwz12 with SMTP id 12so1615701bwz.13 for ; Sun, 20 Feb 2011 10:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=y5pYrZLSKAKSMZXkmCDQSWgwD0YZVnAq17iThLP1SFk=; b=xU1Awk3D42F4XzkMAjPNmrLHSEFHoTWQ22R4WYXFCiZPkE4InPl9q6YkQFVQybXK3x VgWzuBhu2DFYKQELNdTdfMSNivrnfYm/ZAqQ9gG9X7cKK76uurR7BPSA0ohuD7rN/nu9 X77bxtNbQuol65+20QyZSxltQS/YHFpufU62E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=WqzEXpadb8wQJaoy/l+FHKIMdGF7asFB5agNRAeAL52Co1C/Je60hTfBWJ7ovbnoB2 atNhsf9WKKpGTHbDhKsFcqEp0CdrT5j8WztmPV8QBHl2Rg8S1gCRMHlh3+Got0k7eygQ gLDYBUEqayXEo6Icpd3Z/2id7RXd82Yket+sg= Received: by 10.204.60.17 with SMTP id n17mr488138bkh.190.1298225503821; Sun, 20 Feb 2011 10:11:43 -0800 (PST) Received: from Abricot.malikania.fr (65.21.102-84.rev.gaoland.net [84.102.21.65]) by mx.google.com with ESMTPS id j11sm3148215bka.12.2011.02.20.10.11.41 (version=SSLv3 cipher=OTHER); Sun, 20 Feb 2011 10:11:42 -0800 (PST) Message-ID: <4D61599E.4040008@gmail.com> Date: Sun, 20 Feb 2011 19:12:46 +0100 From: David Demelier User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.2.13) Gecko/20110126 Thunderbird/3.1.7 MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: 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:11:47 -0000 On 20/02/2011 18:40, Warren Block wrote: > $() 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. > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" I'd prefere $() rather than ``. It's more powerful, for example you can write a multiple $() but not `` see : markand@Abricot ~ $ echo $(basename $(which dmesg)) dmesg markand@Abricot ~ $ echo `basename `which dmesg`` usage: basename string [suffix] basename [-a] [-s suffix] string [...] which dmesg Of course the example code is useless but shows the limitations of ``. Nowadays all shells supports $() so I advise you to use it :). Cheers, -- David Demelier