I thought of playing around a bit with find -fprintf
. In case you don't know what -fprintf
does, it is the same as -printf
but writing to a file you specify its name.
Now, when I run a command like this:
find -maxdepth 1 -type d -fprintf output "%p\b\n"
I get the following in output
(using vim
and pretty much any text editor):
.^H
./directory-1^H
./directory-2^H
./directory-3^H
I understand that ^H
is the backspace character. Opening output
with less
:
./directory-
./directory-
./directory-
So, the question is:
- Why do
vim
and other text editors (triednano
, andemacs
) display the backspace without interpreting it by removing the character before it butless
does? - Why don't the editors print a character for
\n
instead of going down for a new line? - What is the difference between printing a backspace and hitting backspace on the keyboard (a character gets actually deleted on hitting backspace on the keyboard)?
I'm running this on my machine (laptop) without sshing anywhere. Using GNU/Linux Ubuntu 16.04 LTS with konsole and tmux.
\n
instead of going down for a new line? And what is the difference between printing a backspace and hitting backspace on the keyboard (a character gets actually deleted on hitting backspace on the keyboard)?printf
and backspace (\b
) without a file,I wanted to say the following about output on abash
terminal. (I didn't wantfprintf
.) Let's use printing an array within square brackets with delimiter,,
- python style. From mybash
(on Cygwin, BTW), declarearr=( 1 2 3 4 )
. First look without backspace:printf '['; printf '%s, ' "${arr[@]}"; printf ']'
=> output[1, 2, 3, 4, ]
. If we think the comma and space (2 characters) are "extra", use 2 '\b
', i.e.printf '['; printf '%s, ' "${arr[@]}"; printf '\b\b]'
, => output[1, 2, 3, 4]
.printf '[' >> myfile; printf '%s, ' "${arr[@]}" >> myfile; printf '\b\b]' >> myfile
, I get the same behavior you do. I start withcat myfile
(oh no! the vicious "cat
for display"), and get[1, 2, 3, 4]
. Next,less myfile
gives me[1, 2, 3, 4]
(and I press [q]). Usingvim myfile
, (unless I change formatting options, e.g. by using.vimrc
), I get[1, 2, 3, 4, ^H^H]
. Same result withemacs myfile
as withvim myfile
. If you wantcat
to output in the format ofvim
andemacs
,cat -ETv myfile
gives output[1, 2, 3, 4, ^H^H]
.