Enter key is different from Carriage Return (CR)

Your terminal sends carriage return when you press Enter, and on Unix-like systems, the terminal driver translates that into line-feed ("newline").

That's the icrnl feature shown by stty -a, e.g.,

$ stty -a
speed 38400 baud; rows 40; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

Programs (even shell scripts) can turn that off to read the actual carriage return character to distinguish it from ControlJ (line feed).


The Enter key does send a CR character (carriage return, Ctrl+M, numerical value 13 = 0x0d = 015). You can see that at a shell prompt or in Vi insert mode by pressing Ctrl+V then Enter: Ctrl+V is a keyboard shortcut to enter the next character literally in the kernel's built-in terminal driver as well as in many terminal-based programs including typical shell and Vi(m).

In Vi(m) insert mode, the character Ctrl+M is bound to the command “insert line break”. Vi reacts to most input characters by inserting that characters, but there are a few exceptions, most obviously the character Ctrl+[ which is what the Esc key sends.

In a text file, a line break is represented by a LF character (line feed, Ctrl+J, numerical value 10 = 0x0a = 013).

Pressing Ctrl+J in Vi would actually have the same effect, but you could bind the two keystrokes to separate commands if you wanted. You can observe a difference between Ctrl+J and Ctrl+M in command mode: Ctrl+J simply moves the cursor down to the next line whereas Ctrl+M moves the cursor down to the next line and also moves it to the first non-blank character.