backspace character wiredness

Posted by mykhal on Stack Overflow See other posts from Stack Overflow or by mykhal
Published on 2010-05-18T10:27:45Z Indexed on 2010/05/18 10:30 UTC
Read the original article Hit count: 319

Filed under:
|
|
|

i wonder why backspace character in common linux terminals does not actually erase the characters, when printed (which normally works when typed)..

this works as expected:

$ echo -e "abc\b\b\bxyz"
xyz

(\b evaluates to backspace, can be inserted also as ctrl-v ctrl-h - rendered as ^H (0x08))

but when there are less characters after the backspaces, the strange behavior is revealed:

$ echo -e "abc\b\b\bx"
xbc

is behaves like left arrow keys instead of backspace:

$ echo -e "abc\e[D\e[D\e[Dx"
xbc

erase line back works normally:

$ echo -e "abc\e[1Kx"
x

in fact, when i type ctrl-v <BS> in terminal, ^? (0x7f) is yielded instead of ^H, this is DEL ascii character, but ctrl-v <DEL> produces <ESC>[3~, but it is another story..

so can someone explain why printed backspace character does not erase the characters?

(my environment it xterm linux and some other terminal emulators, $TERM == xterm, tried vt100, linux as well)

© Stack Overflow or respective owner

Related posts about backspace

Related posts about terminal