From owner-freebsd-questions Tue Sep 25 6:28: 2 2001 Delivered-To: freebsd-questions@freebsd.org Received: from Mail6.nc.rr.com (fe6.southeast.rr.com [24.93.67.53]) by hub.freebsd.org (Postfix) with ESMTP id 3802937B43F for ; Tue, 25 Sep 2001 06:27:56 -0700 (PDT) Received: from i8k.babbleon.org ([66.57.85.154]) by Mail6.nc.rr.com with Microsoft SMTPSVC(5.5.1877.687.68); Tue, 25 Sep 2001 09:27:55 -0400 Content-Type: text/plain; charset="iso-8859-1" From: Brian T.Schellenberger To: Salvo Bartolotta , Giorgos Keramidas Subject: Re: silly sed question Date: Tue, 25 Sep 2001 09:27:55 -0400 X-Mailer: KMail [version 1.2] Cc: Mark Rowlands , freebsd-questions@FreeBSD.ORG References: <1001421024.3bb078e00bc61@webmail.neomedia.it> In-Reply-To: <1001421024.3bb078e00bc61@webmail.neomedia.it> MIME-Version: 1.0 Message-Id: <01092509275503.00814@i8k.babbleon.org> Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tuesday 25 September 2001 08:30, Salvo Bartolotta wrote: > > You are probably being bitten by TCSH's stupid quoting, which I NEVER > > actually managed to get the grip of. I tried testing this on sh(1), and > > here's what I came up with: > > > > $ cat myfile > > TARGETS='blob1 blob2 blob3' > > $ sed -e "/^TARGETS/ s/\'$/ blob4\'/" myfile > > TARGETS='blob1 blob2 blob3 blob4' > > Yep, I am afraid you are right: it is tcsh. And I was somewhat cryptic in > my previous message. Sorry. Here's what I do to work around this. In startup scripts, I setenv S '$' setenv Q "'" setenv QQ '"' Then I do things like this with sed -e "/^TARGETS/ s/$Q$S/ blob4$Q/" myfile Good luck. > > IIUC, the quoting game should be played as illustrated in the following > examples: > > > 377 2:10pm ~/trial >====> echo $SHELL > /bin/tcsh > > > 378 2:11pm ~/trial >====> cat example > TARGETS='blob1 blob2 blob3' > 'blob5 blob6 blob7' > > > 379 2:11pm ~/trial >====> sed -e '/^TARGETS=/s/'\''$/ blob4'\''/' example > TARGETS='blob1 blob2 blob3 blob4' > 'blob5 blob6 blob7' > > # Single quotes: beware of the `'' character. > # Notice the matching pairs of `''. > > > > 380 2:11pm ~/trial >====> sed -e "/^TARGETS=/s/'"\$"/ blob4'/" example > TARGETS='blob1 blob2 blob3 blob4' > 'blob5 blob6 blob7' > > # Double quotes: beware of `$'. > # Notice the matching pairs of `"'. > # `'' needs no escaping inside double quotes. > # In tcsh, this is a simple way to work around the "illegal variable > error". > > > However, in sh: > > $ cat example > TARGETS='blob1 blob2 blob3' > 'blob5 blob6 blob7' > > > $ sed -e '/^TARGETS=/s/'\''$/ blob4'\''/' example > TARGETS='blob1 blob2 blob3 blob4' > 'blob5 blob6 blob7' > > # Single quotes: beware of the `'' character. > # Notice the matching pairs of `''. > > > $ sed -e "/^TARGETS=/s/'$/ blob4'/" example > TARGETS='blob1 blob2 blob3 blob4' > 'blob5 blob6 blob7' > > # `'' inside double quotes needs no escaping. > # A $-keyed variable inside double quotes is normally expanded. > # > # Double quotes: in this command, `'' and `$' cause no problem. > # As to the present example, this is probably the simplest form of the > command. > > -- Salvo (going out and sed'ing someone :-)) > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message -- Brian T. Schellenberger . . . . . . . bts@wnt.sas.com (work) Brian, the man from Babble-On . . . . bts@babbleon.org (personal) http://www.babbleon.org --------------------> Free Dmitry Sklyarov! <------------------------- http://www.eff.org http://www.programming-freedom.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message