[Unison-hackers] Re: Bug in / patch for Unison 2.12.0's
Makefile.OCaml
Zvezdan Petkovic
zpetkovic at acm.org
Tue Jun 21 01:17:18 EDT 2005
On Mon, Jun 20, 2005 at 10:46:14PM -0400, Benjamin Pierce wrote:
> Thanks for the suggestion, Nick. I've made this change in the source.
> (If someone can try it out on Windows, that would be great.)
You might want to retract a part of it. :-)
> >
> > The literal control-M can be represented by "\r".
> >
WRONG!
According to POSIX sed uses _basic_ regular expressions.
OTOH, awk and egrep use _extended_ REs.
> >This seems to work for me on Ubuntu 5.04 and Solaris as well as OS X
> >10.4:
Are you sure about Solaris?
> >
> >OCAMLLIBDIR=$(shell ocamlc -v | sed -n '$p' | sed -e 's/^Standard
> >library directory: //' | sed -e 's/\\/\//g' | sed -e 's/\r//g')
This last part doesn't work in most POSIXly correct sed implementations.
I just tested it on OpenBSD, HP-UX, _and_ Solaris.
The file is:
aaa
a^Mb
bbb
Now,
$ cat t
aaa
b
bbb
You can't see a in the second line because ^M returns to the beginning
of the line and prints b over it. Lets test how sed works:
$ cat t | sed 's/\r//g'
aaa
b
bbb
No change when I redirect the output into the file.
The ^M is still there.
Now, using Ctrl-V Ctrl-M to type ^M I get.
$ cat t | sed 's/^M//g'
aaa
ab
bbb
Now it works.
And that is the only way it will work on OpenBSD, HP-UX _and_ Solaris.
Here's a fingerprint of all machines I ran it on without success when \r
is used.
$ uname -rs
OpenBSD 3.7
$ uname -rs
HP-UX B.11.11
$ uname -rs
SunOS 5.9
The only machine where it succeeded for me is:
$ uname -rs
Linux 2.6.5-7.155.29-smp
> >
> >I haven't tested it on Windows.
> >
Considering that Microsoft Services for UNIX return
OpenBSD
when you type
string /usr/bin/* | grep BSD
and it seems some very old rip-off version, I'll bet it will work the
same on Windows on my office machine.
Now, Cygwin could be a different beast being based on Linux.
The bottom line is that \r in sed is _not_ portable.
Keep ^M there.
There's a good reason it was there for so long time.
Welcome to the friendly world of UNIX portability.
:-)
Zvezdan Petkovic
More information about the Unison-hackers
mailing list