Subject: Re: When is \n converted to \r\n? and why?
From: [email-masked] (Christopher G. Faylor)

30 Oct 1998 17:01:30 GMT
Message-ID: <[email-masked]>
References: <Pine.GSO.3.96.981028153437.966D-100000.cygnus.gnu-win32@fungus>
X-Newsreader: trn 4.0-test63 (15 March 1998)

In article <Pine.GSO.3.96.981028153437.966D-100000.cygnus.gnu-win32@fungus>,
Urban Widmark <[email-masked]> wrote:
>(using cygwin32 19.3 & 19.1?)
>
>If I create a small example file:
>
>$ echo a > xx
>$ ls -l xx
>-rw-r--r--   1 544      everyone        3 Oct 28 15:43 xx
>
>it will contain "a\r\n" since I use the default (non-binary mounts)
>
>But if I do:
>$ echo a | wc -c
>      2
>
>I get only 2 chars ... ok, so the translation is done when writing to
>disk.

Depending on the shell you're using, pipes will default to
binary mode.  That's obviously the case here.

>Then something like this will fail:
>
>$ echo a | tr -d '\r' > yy
>$ ls -l yy
>-rw-r--r--   1 544      everyone        3 Oct 28 15:48 yy
>
>So how am I supposed to remove the \r from the echo output?  Well, I know
>non-cygwin ways to remove the \r, the issue is if this is a tr bug, a

If you think that tr should operate on its input and output in a
binary fashion then it is a tr bug for not setting its stdout to
binary.  Possibly, setting CYGWIN32=binmode will work.

>It's also strange that writing to a pipe is different from writing to
>disk, that seems very non-unix'ish. I think it would be better if
>conversion could be toggled by changing an environment variable, it should
>not depend on the destination of my output.

See above.  How this operates also depends on whether the shell you're
using sets pipes to binmode or not.
-- 
[email-masked]
http://www.cygnus.com/