Line endings: LF and CRLF
In short: Windows ends lines with two characters (CR+LF), Linux and macOS with one (LF). The difference keeps causing trouble in scripts and Git.
In more detail: CR (“carriage return”) and LF (“line feed”) come from typewriters and teleprinters. Windows kept both, Unix only LF.
In Depth
- Symptoms: A shell script with CRLF aborts with
bad interpreter: /bin/bash^M. Files look single-lined in old editors or show^M. - Git:
core.autocrlfconverts on checkin and checkout. More reliable is a.gitattributesfile with* text=autoand*.sh text eol=lf. - Converting:
dos2unixandunix2dos, the “line ending” setting in editors. - Protocols: HTTP, SMTP and many text protocols require CRLF, even on Linux.
- Old Macs: Formerly only CR, no longer common.
- Note: In Python text mode, line endings are normalised on reading (
\n).
See also: git rebase