This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: sed anomaly in bash script
- 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
- Authentication-results: sourceware.org; auth=none
- References: <CABa6CE=OFjPjomA9xQESG==MTjP9y=5UqeTgtg4fxnZjYqTEuw at mail dot gmail dot com>
On 11/14/14, 9:20 AM, "cyg Simple" <cygsimple@gmail.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