End of Line Characters

There is an incompatibility among different systems -- Windows, Linux, Mac OS 9, and Mac OS X --
that sometimes causes difficulties when transferring files among systems.

The problem is that the end of line is indicated differently in different systems. For historical reasons, there are two different commands that one can issue:

Historical Note

In dot matrix printers, and even more ancient technology, like IBM selectric electric typewriters, where a print head moves across a line from left to right printing characters, CR made the head go to the leftmost character of the line, while LF advanced the paper, so a new line could be printed. For this reason, LF was sometimes also called "newline", hence the perl \n.

In even more ancient technology the, manual typewriter, the paper was held in a moving "carriage" that carried it past a fixed position where ink-covered keys struck the paper, imprinting the appropriate letter. After the letter was struck, the carriage automatically advanced. When a new line was needed, the carriage had to be returned manually to its initial position. A clever mechanism consisted of a lever, that, when one pushed the carriage left, also turned the cylinder holding the paper, exposing a new line. So the manual action at the end of a line was both a carriage return and a line feed. In many electric typewriters there was a return key that did the same. In some, there was a newline key that just advanced the paper.

With the advent of terminals there was a question of how to translate these commands onto a keyboard.

The state of Confusion

As one would expect, there isn't a standard way to decide what a return should do at the end of a line. The choices are:

Mac OS X is a mix of Unix and old Mac System. Mostly, lines end with LF.

Most programs running on these machines append the appropriate "end of line character" when you hit return, or if the system has another indication that a line has ended.

Some Legitimate Questions.

  1. Why?

    Mostly because different manufacturers wanted proprietary systems, and some assurance that their systems were not being copied.

  2. Why should I care?

    That is easy. Because unexpected extra characters, or lack of control characters can totally mess up your programs. If you copy a file exactly between incompatible systems, you will end up with bogus characters all over your file.

  3. What can I do?