delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/11/14/13:10:48

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:to:date:subject:message-id:references
:in-reply-to:content-type:content-transfer-encoding
:mime-version; q=dns; s=default; b=YP8PCj7h3vjsTU7WEJFrl8qHhhkJx
YUvXOicDLnnMKcOLjxLHkB/CCFOd6aI7krVFGa9SIq/+3Roe3ft0TI4vS1m2aS2T
2dM3tGnO1rNV2wS1/Kn5ksa8m4GNn856bV/as8b+z0Q45lrs2fJM3er94sR9HFzf
WjOhVoTLZpslj4=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:to:date:subject:message-id:references
:in-reply-to:content-type:content-transfer-encoding
:mime-version; s=default; bh=fdEYe4eeIxr29i+/zKOu2jMqQ9w=; b=nff
WuDuSL66vNRc2eUTOhLuoR3WS3fJvtCyC54hc36SuypESDe9dupOVAQ+us2LKMy/
djVazs5+VvOQvUmunW/aVgKkDQfU18dAi1Oe8dRUtuglIrOqOqmeE1AIZoNpP3bd
mGR69LAvMRDvObl8l3Ymg5O0PkVRS9EMlaYdS6zw=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2
X-HELO: tus1smtoutpex03.symantec.com
From: Bob McGowan <Bob_McGowan AT symantec DOT com>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Date: Fri, 14 Nov 2014 10:10:21 -0800
Subject: Re: sed anomaly in bash script
Message-ID: <D08B838A.67F5%bob_mcgowan@symantec.com>
References: <CABa6CE=OFjPjomA9xQESG==MTjP9y=5UqeTgtg4fxnZjYqTEuw AT mail DOT gmail DOT com>
In-Reply-To: <CABa6CE=OFjPjomA9xQESG==MTjP9y=5UqeTgtg4fxnZjYqTEuw@mail.gmail.com>
user-agent: Microsoft-MacOutlook/14.4.4.140807
MIME-Version: 1.0
X-CFilter-Loop: Reflected
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id sAEIAhM1003436

On 11/14/14, 9:20 AM, "cyg Simple" <cygsimple AT gmail DOT com> wrote:

>$ TEST=`echo 'c:\windows' | sed -e s.\\.\\\\.g`
>$ echo $TEST
>c:\\windows
>
><file name=sed.sh>
>TEST=`echo 'c:\windows' | sed -e s.\\\.\\\\\.g'
>echo $TEST
></file>
>
>$ bash -x sed.sh
>++ echo 'c:\windows'
>++ sed -e 's.\.\g'
>sed -e expression #1, char 7: unterminated 's' command
>+ TEST=
>+ echo
>
>CYGWIN_NT-6.1 HOSTNAME 1.7.32(0.274/5/3) 2014-08-13 23:06 x86_64 Cygwin
>
>Does anyone have a suggestion on turning c:\windows into c:\\windows?
>
>Thanks,
>-- 
>cyg Simple
>

The combination of shell globbing and sed metacharacters, with appropriate
escaping, is rather difficult, and nearly impossible to read.

I would suggest using the 'sed -f file' so you can completely eliminate
any shell processing.

The file should contain the string 's/\\/\\\\/', without the quotes ;)

Of course, if you want your script to be in a single file, this won't
work, so one of the other responders answers may be more suitable.

FYI, I would suggest not using the dot as a pattern separator, it could be
confusing to novice readers, and also removes it as a pattern match
character.

Bob


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019