Subject: \r\n

From: "Arik Baratz" <[email-masked]>
Date: Wed, 5 Jun 2002 15:15:47 +0200

I have a question for you all.

We all know that the UNIX convention for the end-of-line character is a CR (0x0d), while the DOS/Windows convention is CR/LF (0x0d 0x0a).

When did the practice of using CR/LF begin? Did Bill Gates steal it from CP/M? I know VMS follows the UNIX convention - can't be from there.

What is the historical reason for it? Surely if a printer works under UNIX it doesn't need the extra LF.

Arik Baratz
System Engineer

Office:
13 Hasadna St.					Tel:    +972 (9) 743-9250 ext. 114
Raa'nana 43661				Fax:   +972 (9) 743-9251
ISRAEL

This email may contain confidential information. You may not deliver this message to anyone without my consent.

If this message is not intended for you, Please destroy this message and kindly notify me by replying this mail.

Anything in this message that do not relate to the official business of Vidius is my own responsibility.

********************************************************
This email has been scanned by Port Authority.

********************************************************

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 5 Jun 2002 15:54:03 +0300

> We all know that the UNIX convention for the end-of-line character is a CR (0x0d), while the DOS/Windows convention is CR/LF (0x0d 0x0a).

It is LF-only in UNIX, not CR-ONLY.

> What is the historical reason for it? Surely if a printer works under UNIX it doesn't need the extra LF.

If you think for a moment about the names "carriage return" and "line feed"
and how a typewriter (and old teletype terminals) worked, you'll figure
out the answer easily.

But if you still don't understand, here's the explanation: A typewriter (I
hope you've seen one :)) has two distinct "operations":
 1) "Line feed", rotating the drum on which the paper is layed out, moves
    the paper one row down, but the head stays in the same column.
 2) "Carriage return" returns the carriage (the thing in charge of holding
    the head and moving it forward every time you type a character) to the
    beginning of the line.

Hence, when you wanted to go to the beginning of the next line on a printer,
you'd need to output *both* a carriage-return and a line feed characters.
This was always true even in Unix terminals (Unix started on typewriter/
printer-like teles, but even on CRT terminals, this was emulated and LF used
to move to the same column on the next line and CR used to go to the first
column of this line).

But the UNIX guys realized that such implementation issue is no reason to
put this idiotic CR-LF sequence into files; CR-LF not only takes more space,
but is also more ambigious (what do you do if there is only a CR with no LF
after it? What do you do if you have them in reverse order?). So the UNIX
convention (I don't know if UNIX took this idea from an earlier OS) became
that new lines are signified by LF everywhere, and it is the job of the
terminal driver to convert a LF to a CR/LF if the underlying terminal needs
this sequence for proper display. You had (and probably still have) stty
commands like "onlcr" to control that behavior in the terminal driver
(a.k.a. "line discipline").

-- 
Nadav Har'El                        |     Wednesday, Jun 5 2002, 25 Sivan 5762
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Attention: There will be a rain dance
http://nadav.harel.org.il           |Friday night, weather permitting.