People usually want to see what they're typing (unless it's a password) :-)
The terminal accepts input at any time, and buffers it until an application reads it. More than that, when the tty is in cooked mode, the kernel buffers whole lines at a time and provides some rudimentary line editing functionality that allow you to kill the entire buffered line (default binding Ctrl-u and backspace. During the time that the line is being entered and edited and until you press Enter, applications reading from the terminal read nothing at all.
The tty functionality in the kernel does not and can not know if and when an application like tail
is planning to produce output on the terminal, so it would not be able to somehow... cancel (?) line editing during such times and only during such times.
Anyway, being able to prepare the next line for the shell while something else is still busy running on the terminal and the shell is not yet ready to read that command is a feature, not a bug, so I wouldn't advocate removing it. Maybe not so useful for tail
(which will never terminate on its own), but pre-typing the next command during a long-running cp
or make
(for example), and even editing that command with Ctrl-h and Ctrl-u, all before the shell gets ahold of it, is a common thing to do. Timothy Martin wrote in a comment:
It is worth mentioning that less +F somefile
provides similar functionality to tail -f somefile
except that (accidentally) typed keystrokes will not echo
to the screen.
Yeah, but less
not only prevents those characters from being echoed, but it also eats them, so they are not available to the next application that wants to read them!
Finally, there is one more reason:
In historical times (before my time!) terminals with local echo were common. That is, the terminal (usually in hardware) would echo the characters you typed locally while also sending them down the serial line. This is useful for giving the user quick feedback even if there was lots of latency over the conection to the UNIX system (think 300 baud modem dialing up a terminal server with auto-telnet to a slow UNIX system over a token ring network — or whatever).
If you have a terminal with local echo, then you want stty -echo
at all times on the UNIX server to which you are connected. The result is approximately the same as a terminak without local echo (the common kind today) and stty echo
enabled. So from that point of view, stty echo
's job is to echo charatcers immediately as soon as they are received, regardless of what software is running, in emulation of what would happen on a terminal with local echo.
(By the way, if you have a terminal with local echo, you can't hide your password.)
Don't copy multiple lines of text, to paste. I can almost guarantee you're simply copying the last part of the line. If you're triple clicking to copy that line of code you're pasting, you're getting the newline at the end of the line. If you want to be sure, that is really the problem, then copy the entire line, except for the last letter/digit, and see if pasting that also includes a newline.
Best Answer
A shell is just an application running in a terminal. For pasting, only emulators relevant, but there are still "real" terminals (hint: the Linux console is not one of those).
Disregarding the various console implementations, because pasting text is done in a more limited manner, the terminals running in X are the point of the question. A terminal emulator simply sees a series of events. Typed keys or pasted text look the same to the terminal emulator.
Considering just terminal emulators (and select/paste between those), backspace is not a problem because select/paste work with what's displayed on the terminal's window. That is, if a user selects text on a terminal's window, only printable text (with possibly tab characters as a special case). There aren't any backspace characters (unless someone's got a buggy terminal implementation), because a backspace tells the terminal to move the cursor left. There's no printable reside left for the terminal to provide in a selection. There are hundreds of other terminal controls which might be used, but backspace is simple and widely used.
Backspace is a problem with poorly implemented applications such as browsers (which really should provide displays of printable text...), that apparently will store whatever some script-writer decides should be stored on the screen.
So... rather than ask why terminal emulators still allow BS, one might ask why GUI browsers allow this behavior.