From owner-freebsd-questions Tue Sep 25 5:30:41 2001 Delivered-To: freebsd-questions@freebsd.org Received: from aragorn.neomedia.it (aragorn.neomedia.it [195.103.207.6]) by hub.freebsd.org (Postfix) with ESMTP id D018937B445 for ; Tue, 25 Sep 2001 05:30:36 -0700 (PDT) Received: (from httpd@localhost) by aragorn.neomedia.it (8.11.4/8.11.4) id f8PCUOM30640; Tue, 25 Sep 2001 14:30:24 +0200 (CEST) To: Giorgos Keramidas Subject: Re: silly sed question Message-ID: <1001421024.3bb078e00bc61@webmail.neomedia.it> Date: Tue, 25 Sep 2001 14:30:24 +0200 (CEST) From: Salvo Bartolotta Cc: Mark Rowlands , freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: IMP/PHP IMAP webmail program 2.2.4-cvs X-WebMail-Company: Neomedia s.a.s. X-Originating-IP: 62.98.153.99 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 > 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. 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