In many Linux distributions I come across, backspace characters are included when pasting text into a shell. Why is pasting of these characters not prevented – or does this feature provide some useful functionality?

In other words, does the Linux shell “know” if it’s a pasted string – or typed by hand?

How is this behaviour handled?

  • 2
  • 2
    As to why terminal emulators still allow BS I'm not sure, we'd have to ask @ThomasDickey. Possibly it might be to help with the pasting of nroff-generated bold/underlined text, but I'm not sure how that could end up in the clipboard in the first place. Commented Mar 13, 2018 at 10:03
  • To follow on from @StéphaneChazelas comments, Thomas Dickey provided a very informative answer to a question I asked on the (historic) usefulness of being able to send a backspace control character: unix.stackexchange.com/a/274795/22812 It would be interesting to know if there are any good reasons to support this feature in modern terminals (and emulators). Commented Mar 15, 2018 at 14:20

1 Answer 1


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.

  • A terminal emulator simply sees a series of events. Typed keys or pasted text look the same to the terminal emulator this answered my question. not only, I ignored any difference between a real and an emulator terminal. thank you for pointing GUI browsers issue.
    – Curcuma_
    Commented Mar 15, 2018 at 8:43
  • 4
    But you did add the stripping of control characters in 292 (invisible-island.net/xterm/xterm.log.html#xterm_292), presumably to guard against those broken applications like browsers that add them there in the first place (note that others like gvim or anything that sets the selections to any arbitrary data do as well), but why not BS (nor DEL)? What's the use case? Commented Mar 15, 2018 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .