Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echoing a backspace

Tags:

bash

echo

Is it possible to echo a backspace in bash?

Something like

echo $'stack\b' 

Shouldn't output stac? Or I'm missing something?

More specifically, I'd like to use that in:

ls | wc -l; echo $'\b items' 
like image 952
sidyll Avatar asked Apr 19 '11 23:04

sidyll


People also ask

How do you backspace in Unix?

you can use '\r' too. note that backspace does not clear anything - only moves the cursor back.


1 Answers

\b makes the cursor move left, but it does not erase the character. Output a space if you want to erase it.

For some distributions you may also need to use -e switch of echo:

  -e     enable interpretation of backslash escapes 

So it will look like

 echo -e 'stack\b ' 

Also, files=(*) ; echo "${#files[@]} items".

like image 74
Ignacio Vazquez-Abrams Avatar answered Sep 20 '22 14:09

Ignacio Vazquez-Abrams