Erase character with BackSpace on a bash command line
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
Related videos on Youtube
![luisascoobydoo](https://i.stack.imgur.com/NOnP1.jpg?s=256&g=1)
luisascoobydoo
Updated on September 18, 2022Comments
-
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 over 7 yearsHi 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 over 7 yearsYou didn't give any details on the contents of your files, the answer addressed the limited information which was given.
-
luisascoobydoo over 7 yearspastebin.com/SVd1KJYk <-- Bashrc
-
luisascoobydoo over 7 yearspastebin.com/D92zNzkK <-- profile
-
Marius over 7 yearsI'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 over 4 yearsThis 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 about 4 yearsI am unable to assing both
ctrl-h
and backspace together. Like ifctrl-h
works backspace returns^?
-
alper almost 3 yearsif we are using
zsh
, should we havestty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"
in.zprofile
or can we have it in.zshrc
?