limon limon - 1 year ago 126
Bash Question

^H in bash variable

echo "hello^H^H" #hello
echo "hello^H^H " #hel o

I know ^H deletes back a letter in console. But why the first echo has no effect and second one gets "hel o".

Answer Source

The backspace just moves the cursor one position to the right without actually erasing what's printed on the screen. Only your second instruction actually erases the 4th character by overwriting it with the trailing space in your string.

I'll try to visualize it:

$ echo "hello^H^H"
   `-- cursor position
$ echo "hello^H^H "
hel o
    `-- cursor position
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download