I guess by “enter” you mean the Return key of your keyboard, probably labeled ↵.
Back in the seventies, we usedwere transitioning from ttys to CRT-based computer computer terminals. Some of these, such as the VT50 or VT100,Early terminals had keyboards with separate keys for CR and LF. On the DEC VT05, these were labeled, quite appropriately, ReturnCR and Line FeedLF keys. On the VT50 and VT100 series, which respectively sent CRthey were labeled RETURN and LF through the serial line. Eventually, the Line FeedLINE FEED. Later key gotmodels dropped on newer models,the LINE FEED key and we ended up with the Return and no key alonefor LF. TodayNowadays, these bulky terminals have been replacedhave been replaced by terminal emulators such as rxvt or gnome-terminal. However, asHowever, as the name implies, a terminal emulator's job is… to emulate a terminal! Thus, the situation hasn't changed that much: the Return still means key still stands for CR, just as it did in 1975.
On the other hand, Unix standardized on using LF as the end-of-line indicator. Both in text files and in user-space programs, lines of text are always terminated by LF. This begs the question: how cando we then interact with a Unix (or Linux) system using a terminal that sends CRmakes sending LF a lot every time we press Returnharder than sending CR? The answer is… it depends on what specific specific programprogram we are interacting with.
When we interact with a “naive” program, or at leastrather a program that
wouldn'tdoesn't bother to handle the terminal, the in-kernel terminal driver is
in “canonical” (or “cooked”) mode. In this mode, it translates the
incoming CR characters
characters coming from the terminal to LF, and the outgoing LFs to CR+LF sequences.
Thesesequences. These translations can be seen as the icrnl
and onlcr
flags
flags in the
output output of stty -a
.
Some programs prefer to handle the terminal themselves: they instruct
the terminal driverinstruct
the terminal driver to refrain from doing character conversions
conversions (they
set set it to “raw” mode) and handle these conversions themselves
themselves. Most
often often this is done within a library such as readline
readline or ncursesncurses. Bash is
one one of those programs (it uses readline
readline) but, thankfully, it resets the
terminal terminal to cooked mode before
exec()
-ing other programs.
Now, imagine you want to talk to some sort of device that speaks text on a serial port. You go to your attic and grab your old VT420VT420 that has been collecting dust there for the past 30+almost 30 years. You hook it to your device using a cross-over (“null-modem”) cable, and voilà! Your device has a terminal! How cool is that? Hopefully, this device has been designed to play nicely with a classic terminal: it expects CR-terminated messages, because the VT420 does not have a dedicated Line Feed key. OtherwiseIf it expected LF instead, then you would have to to end your lines with by typing Ctrl-J, as the VT420 has no dedicated LINE FEED key.
If you don't own any of these lovely vintage terminals, you couldcan use an emulatedinstead an emulated one such as gnome-terminal (or maybe evenor cool-retro-term),. and use minicom (orYou connect it to your device using a communication program such as minicom, or picocom) instead of the null, and a USB-modem cableto-serial converter. In their their default configuration configuration, these communication programs do not mess with your data stream: they configure the tty driver in raw mode (on both ends), and they forward the bytes faithfully between your emulated terminal and your device, just like athe null-modem cable would do with your VT420. But But unlike a null null-modem cable, you can configure picocom can be configured to translate the line endingsthe line endings on the fly if needed.