Daily Shaarli

All links of one day in a single page.

March 22, 2023

tty - When will an interactively typed backspace be passed as input? - Unix & Linux Stack Exchange

That's determined by a) what characters does the terminal emulator send when the BackSpace key is pressed (^H/BS or ^?/DEL) and b) what character is used as VERASE by the tty driver (see and change the latter with stty(1) -- stty erase ^H).

If the terminal emulator is sending ^H but the tty isn't recognizing it as a special character, presssing the BackSpace key will visually "erase" the last character on the screen[1], but the character will be sent as-is (together with the character before it) to the process reading from the tty (cat).

Editors and interactive programs with line-editing capabilities set the tty to raw mode and do their own handling of special characters, and may treat ^H and ^? the same; cat isn't one of those ;-)

[1] this is subject to the echoctl stty setting -- if that is set, the terminal will echo control characters back in the "^"+chr(char^0x40) format (^H for BS = 8, etc).