* sed anomaly in bash script
@ 2014-11-14 17:20 cyg Simple
2014-11-14 17:45 ` Cliff Hones
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: cyg Simple @ 2014-11-14 17:20 UTC (permalink / raw)
To: cygwin
$ 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
--
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed anomaly in bash script
2014-11-14 17:20 sed anomaly in bash script cyg Simple
@ 2014-11-14 17:45 ` Cliff Hones
2014-11-14 17:48 ` David Stacey
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Cliff Hones @ 2014-11-14 17:45 UTC (permalink / raw)
To: cygwin
On 14/11/2014 17:20, cyg Simple 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?
Try:
TEST=$(echo 'c:\windows' | sed -e 's.\\.\\\\.g')
echo $TEST
-- Cliff
--
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed anomaly in bash script
2014-11-14 17:20 sed anomaly in bash script cyg Simple
2014-11-14 17:45 ` Cliff Hones
@ 2014-11-14 17:48 ` David Stacey
2014-11-14 18:10 ` Bob McGowan
2014-11-15 4:41 ` Brian Inglis
3 siblings, 0 replies; 5+ messages in thread
From: David Stacey @ 2014-11-14 17:48 UTC (permalink / raw)
To: cygwin
On 14/11/14 17:20, cyg Simple 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?
I don't have a Windows PC to hand ATM, but the following works in Fedora
bash:
#!/usr/bin/bash
TEST=$(echo "c:\windows" | sed -e "s;\\\\;\\\\\\\\;g")
echo ${TEST}
Dave.
--
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed anomaly in bash script
2014-11-14 17:20 sed anomaly in bash script cyg Simple
2014-11-14 17:45 ` Cliff Hones
2014-11-14 17:48 ` David Stacey
@ 2014-11-14 18:10 ` Bob McGowan
2014-11-15 4:41 ` Brian Inglis
3 siblings, 0 replies; 5+ messages in thread
From: Bob McGowan @ 2014-11-14 18:10 UTC (permalink / raw)
To: cygwin
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sed anomaly in bash script
2014-11-14 17:20 sed anomaly in bash script cyg Simple
` (2 preceding siblings ...)
2014-11-14 18:10 ` Bob McGowan
@ 2014-11-15 4:41 ` Brian Inglis
3 siblings, 0 replies; 5+ messages in thread
From: Brian Inglis @ 2014-11-15 4:41 UTC (permalink / raw)
To: cygwin
cyg Simple <cygsimple <at> gmail.com> writes:
> $ 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
> Does anyone have a suggestion on turning c:\windows into c:\\windows?
$ t='c:\windows' ; tt=${t/\\/\\\\} ; echo $t $tt
c:\windows c:\\windows
Never ever use odd numbers of backslashes, when dealing with backslashes! ;^>
"\\" is the character backslash, doubled for each layer of interpretation it
has to pass thru before it gets to where it's going.
--
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-11-15 4:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-14 17:20 sed anomaly in bash script cyg Simple
2014-11-14 17:45 ` Cliff Hones
2014-11-14 17:48 ` David Stacey
2014-11-14 18:10 ` Bob McGowan
2014-11-15 4:41 ` Brian Inglis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).