4

In the stty documentation, the following is mentioned:

[-]icrnl translate carriage return to newline

[-]inlcr translate newline to carriage return

* [-]ocrnl translate carriage return to newline

* [-]onlcr translate newline to carriage return-newline

Notice how the "cr" in icrnl and inlcr and ocrnl mean "carriage return" but it means "carriage return-newline" in onlcr.

Is this a typo, or is this how onlcr really works (i.e. it translates \n to \r\n)?

Joseph
  • 375

1 Answers1

3

It is not a typo, it is in fact what POSIX also says:

onlcr (-onlcr)

Map (do not map) NL to CR-NL on output. This shall have the effect of setting (not setting) ONLCR in the termios c_oflag field, as defined in XBD General Terminal Interface.

The fact that the mode isn't called "onlcrnl" is probably just to keep the setting names short and consistent (or at least consistently short).

The Rationale section tells us that the standard for stty was adopted from System V, so I'm assuming there was backward compatibility to older systems to care about too.

Kusalananda
  • 333,661