Erase character with BackSpace on a bash command line

13,501

Solution 1

Generally (depending on the conventions for the particular system you are using), the backspace key sends either ASCII BS (^H) and DEL (^?)

Some terminal emulators switch between ASCII BS (^H) and DEL (^?) when you use the shift-modifier. Some do not. Apparently the program you are using for ssh does not.

Given this line from your .profile:

stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"

it seems that your terminal normally sends ^? (ASCII DEL), but you told it to expect ^H (ASCII BS). However, your terminal switches to ^H when you modify backspace with the shift key. You could have used

stty erase "^?" kill "^U" intr "^C" eof "^D" susp "^Z"

and gotten better results.

Solution 2

I get the feeling there isn't a one-size-fits-all solution. The following fixed the issue in bash 4.1 in gnome-terminal (2.31.3) for me:

stty sane

Ref: Source

Share:
13,501

Related videos on Youtube

luisascoobydoo
Author by

luisascoobydoo

Updated on September 18, 2022

Comments

  • luisascoobydoo
    luisascoobydoo almost 2 years

    I have a configuration for bash and profile files, but I copied that file to other server so now I can't erase text only by pushing backspace, I need to press Shift + Backspace to erase text.

    What is the parameter I need to change to restore it?

  • luisascoobydoo
    luisascoobydoo over 7 years
    Hi Thomas I have this (^?), but that's strange because before I copied the profile files, Work normally, but when I run source.profile changes that backspace erase. also the program is the same for both servers.
  • Marius
    Marius over 7 years
    You didn't give any details on the contents of your files, the answer addressed the limited information which was given.
  • luisascoobydoo
    luisascoobydoo over 7 years
  • luisascoobydoo
    luisascoobydoo over 7 years
    pastebin.com/D92zNzkK <-- profile
  • Marius
    Marius over 7 years
    I'm not certain, but a quick search hints that sqlplus uses the stty erase setting, and if you update your .profile to match the terminal settings (or the terminal to match .profile), then sqlplus will "work".
  • Rich
    Rich over 4 years
    This is the best advice. The top answer's fearsome line of multiple stty overrides is totally unnecessary in all but a few (read: severly broken) cases.
  • alper
    alper about 4 years
    I am unable to assing both ctrl-h and backspace together. Like if ctrl-h works backspace returns ^?
  • alper
    alper almost 3 years
    if we are using zsh, should we have stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z" in .zprofile or can we have it in .zshrc?