In the CentOS, I use:
[root@localhost sbin]# echo -e "ab\bc" ac the \b means backspace.
But when I use:
[root@localhost sbin]# echo -e "abc\b" abc It print out abc, why it do not backspace?
Backspace is not destructive by itself, though most editors (and even the command line) do make it seem that way. What really happens is that those programs, while interactive, make the cursor backup, they then write a space, and backup again to position the cursor correctly.
So your line could be echo -e "abc\b \b" and it'd work then.
You can test this by doing echo -n -e "abc\b" (the -n removes the automatic jump to the next line). Your prompt will now overwrite the 'c'.
This is somewhat similar to \n which means go to the next line (but not to the margin) and \r which is going to the margin (but not to the next line). Operating systems interpret those characters differently (Unix add a next-line to \n, DOS have both chars, etc).
echo -e 'abcdef\b\b\bx' no backspace erase anything, only when the x gets printed, the d gets replaced. \b, which is explicit in echo -e "ab\bc". Not about your description of the key Backspace. In fact, your answer has nothing to do with the question. Sorry. stty erase) can be ^H (BS) or ^? (DEL) depending on your religion. For output, it's ^H, not ^?. Yes, this works as expected (the x character gets removed):
$ echo -e 'ax\bc' ac And yes, it "looks like" the backspace character gets lost with this:
$ echo -e 'abx\b' abx Note that the backspace character (\b) is not the same as the keyboard key Backspace.
The keyboard Backspace prints ^? with Ctrl-VBackspace.
That is interpreted by many editors as move back and remove a character. That is a lot more complex than just printing a white space, the whole line to the right needs to be moved one space (or two for wide characters, or zero for control characters) left for each char erased, or, if the erased character is a new line, move the entire line one line up. No, that is not a simple character, it is an entire procedure connected to the keyboard key Backspace.
However, no, the backspace character is actually written to the console.
You can look at what is being transmitted to the console with od:
$ echo -e 'abx\b' | od -vAn -tx1c 61 62 63 08 0a a b x \b \n So, what happens?
abx gets written to the console.abx to the line buffer.\b gets written to the console.\b cause the console line buffer to move back one character.\n gets printed to the console.That is the default way in which consoles work.
Take a look at this:
$ printf 'abcdef\b\b\b \n' abc ef The character d is the one replaced with a white space.
Why does the 'ax\bc' remove the x?
Because the c character overwrites the character x.