Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Sep 2001 14:30:24 +0200 (CEST)
From:      Salvo Bartolotta <bartequi@neomedia.it>
To:        Giorgos Keramidas <charon@labs.gr>
Cc:        Mark Rowlands <mark.rowlands@minmail.net>, freebsd-questions@freebsd.org
Subject:   Re: silly sed question
Message-ID:  <1001421024.3bb078e00bc61@webmail.neomedia.it>

next in thread | raw e-mail | index | archive | help
> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1001421024.3bb078e00bc61>