LINE TERMINATION PROTOCOLS, TELETYPE MECHANICS & WHITESPACE PURIFICATION
Historical taxonomy of ASCII control codes 0x0D (CR) and 0x0A (LF), Git autocrlf configuration hazards, and payload optimization.
1. Mechanical Teletype Origins (CR vs LF)
In mid-20th-century electromechanical teleprinters (such as the Teletype Model 33), advancing to the start of a subsequent printed line required two physical operations taking distinct mechanical durations:
- Carriage Return (CR / / 0x0D): Moved the physical printing head horizontally back to column index 0 on the left margin.
- Line Feed (LF / / 0x0A): Rotated the platen roller drum upward by one single vertical line.
Because the horizontal carriage return took several milliseconds to complete, transmitting CR + LF sequentially ensured the carriage had safely returned before ink struck the subsequent line.
2. Operating System Divergence & The Git ^M Hazard
When Unix was engineered at Bell Labs in 1969, Dennis Ritchie and Ken Thompson simplified line termination to a single byte:
(LF), conserving precious magnetic core storage. Conversely, CP/M and MS-DOS retained the teleprinter two-byte sequence
(CRLF), which persists today in Microsoft Windows.
When Windows CRLF shell scripts execute on Linux or Docker containers, the shell interprets the trailing
as part of the command name (rendering /bin/bash^M: bad interpreter). Sanitizing files to pure Unix LF prevents catastrophic CI/CD deployment failures.