Shell – Why doesn’t `echo abc^H` just print `ab`

shellspecial charactersterminal

As I recall, ^H means Backspace. I generated it by pressing CTRL+V, CTRL+H.

So the ^H should remove the last character, as it is the same as Backspace and it should act just as if I pressed Backspace at this position.

Why the does the output of echo abc^H remain abc and not ab?

Best Answer

backspace is only moving the cursor backward.

backspace (or delete or whatever character depending on the configuration) deletes the last printed character only when these conditions are met:

  • it is typed on the keyboard, not a command output like echo in your example
  • the terminal device is in cooked mode (the usual case)

If you want to erase the c in your example, you need to overwrite it by another character, for example:

echo "abc^H "
Related Question