There is a server at my work that uses csh as the default shell. I prefer bash, so whenever I login, I start bash.

But for some reason, the backspace button deletes complete words instead of just deleting characters. Why is that? How do I change this and have the Bksp delete char by char??

FYI, Shift+Bksp deletes character by character. If possible, I'd like to have Shift+Bksp delete word by word. Only if possible.


PS: Please don't tell me to hold the shift key; its downright annoying.

  • are you using putty or similar to connect, or is this from anouther nix machine ? – Sirex Oct 26 '10 at 6:50
  • If you do stty -a, does the erase parameter say "^?". If you press Ctrl-v then Backspace, do you see "^?"? Another possibility you may see is "^H". What terminal software are you using? Does Backspace work normally in csh? – Dennis Williamson Oct 26 '10 at 6:51
  • I would check the ˜/.bashrc or ˜/.bash_profile or the same files from /etc/skel if they don't exist in your home folder – Warnaud Oct 26 '10 at 7:08
  • @Sirex Yes, I'm using putty to connect. @Dennis yes, stty -a says erase = ^?. I'm using Putty. Yes, Bksp works okay with csh. Additionally, I see werase = ^? in stty -a output. – Here Be Wolves Oct 26 '10 at 13:21
  • @Warnaud what would I check these files for? What am I looking for? – Here Be Wolves Oct 26 '10 at 14:10

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).

  • Why is it that csh runs okay, but bash has problems with this? When I run stty -a I see erase as well as werase set to '^?. PS: I changed putty's backspace character to ^H` and backspace started working fine. But is there something I can put in .bashrc so I don't have to change putty's config? – Here Be Wolves Oct 29 '10 at 5:18
  • @Here: Since there are contradictory indications about ^?, it could be that csh just happens to read the terminal settings in a different order from bash. You can put stty erase='^W' (the usual setting) in your .bashrc, then you won't have contradictory settings any more and ^? sent by BackSpace should erase a single character. – Gilles 'SO- stop being evil' Oct 29 '10 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.