Bash backspace deleting one word at a time

Solution 1:

Some terminals send ^h (character number 8) for the BackSpace key, and some send ^? (character number 127). Many terminal emulators can be configured, and most programs can be configured to know which key to expect. Obviously the two sides must agree.

Stty is a way in which applications can query the terminal's configuration. erase = ^? means that your terminal description file on the server claims that when your terminal sends ^?, it means “erase the previous character”. werase = ^? means that ^? means “erase the previous word”. There's a contradiction between these two settings.

When you log in over ssh, the ssh client sends a name for the terminal, which is put in the TERM environment variable. Programs on the server then look up descriptions of the terminal in a database (called termcap or terminfo). If these descriptions are broken, or if a configuration file somewhere (such as /etc/profile or ~/.login or ~/.bashrc) overrides the descriptions with wrong data, you might find that you have a mismatch. For example, one possible source for your problem is if some initialization file contains the command stty werase '^?' (forcing ^? to mean a word erase) while your terminal sends ^? for the backspace key.

Ideally, you should fix the conflict, as a lot of programs will read this information.

In Putty, you can configure which of ^? or ^h the BackSpace key sends. Check the value of this setting. Maybe the easiest way to fix your problem is to make Putty send ^h for BackSpace, and make sure the server uses that setting (stty erase '^h', to be put in ~/.bashrc, will force it).