echo backspace

Hello Forum:

I am trying to find a meaning to this echo escape character:

echo -e "\b"

Can someone tell me or give me examples of the effect that this has when used. I know that \b is the backspace, but I cannot visualise it use like any other escape such as:

echo -e "\n"

Thanks.
--Willie

$ echo -e '12345\b6'
12346

Thanks Scrutinizer.

Any others?

Like how carriage returns return the carriage, like how new lines cause a new line, back space moves the cursor back one space. It does not erase, just moves the cursor. This behavior happens wholly within the terminal, backspace is still just another character as far as any programs are concerned:

$ echo -e '12345\b6' | hexdump -C
00000000  31 32 33 34 35 08 36 0a                           |12345.6.|
00000008
$ 

That's really all there is to it.

Further to Corona688.

The settings in "stty -a" matter.

On a conventional DEC vtxx terminal (or emulator) this unix command will turn the backspace key into a destructive erase key.

stty erase "^H"

Thanks methyl.

I believe this might be one of the most abstract escape characters, in my opinion.

--Willie

---------- Post updated at 09:53 PM ---------- Previous update was at 09:52 PM ----------

Thanks Corona688.

Thanks for your time guys.

--Willie

It's all abstract. What makes moving back more abstract than moving forward, down, or to the beginning of the line?

@Corona688:

I want to fully understand how this lines of code do their job:

#!/bin/bash

SAVEIFS=IFS
IFS=$(echo -en "\n\b")

for f in $(cat mp3file.txt)
do
     echo "$f"
done

IFS=$SAVEIFS

I can follow everything, but I cannot follow where IFS would find a backspace as field separator. For example, to loop over a number of song titles such as these ones:

$cat mp3file.txt
01 - Don't Eat the Yellow Snow.mp3
02 - Don't Drink the Rain.mp3
03 - What is Going On?.mp3
04 - Thank You, Thank You.mp3
05 - Back to Life, Back to Theback.mp3

These are not real song titles, but just a group of names I made for testing purposes. I don't see where it is possible that IFS would find the backspace as a field separator here. I guess that is why I find it more abstract than any other.

Thanks.
--Willie

In the ASCII world the Backspace key is not a key which generates an Escape sequence. Neither is the Linefeed key.

...badly, that's how. :stuck_out_tongue: That's a useless use of cat and prone to truncating the list should it exceed the size of a shell variable, and even when it works it's wasteful since it reads the entire list into memory, and a bit of a hack since it uses IFS and argument lists to split lines instead of using the built-in read method. It can be done much better like this:

while read f
do
        echo $f
done < mp3file.txt

As for why IFS had a backspace in it: I have no idea. The shell doesn't process backspaces specially, so maybe his data did have real, literal backspaces in it somehow, but that's not normal. It doesn't do anything for your files, since argument splitting (or read) will break on any character in IFS, not just all of them. It's not good example.

Thanks a lot for the clarification Corona688.