Happy Mittal
Happy Mittal

Reputation: 3747

special character in UNIX

I want to add backspace character literally in my file named junk. So I did following
$ ed
a
my name is happy\b (here b means I typed backspace so \ gets disapperaed and cursor sits sfter y)
.
w junk
q

But when I do
$ od -cb junk
it doesn't show backspace.

Upvotes: 0

Views: 969

Answers (2)

Personman
Personman

Reputation: 2323

Type ctrl-v, ctrl-h.

ctrl-v says 'insert the next control character literally'. The cursor should change to a highlighted caret.

ctrl-h is the backspace character. It looks like in ed, typing ctrl-h without ctrl-v also inserts a literal backspace, but in other contexts, crtl-h may have some other meaning, and you will need to press ctrl-v first.

EDIT: With the above steps, od -cb gave me:

$ od -cb file
0000000   h   e   l   l   o  \b  \n
        150 145 154 154 157 010 012
0000007

which looks correct.

When I tried it again with ctrl-v, Backspace (as opposed to ctrl-h), it instead gave

$ od -cb file
0000000   h   e   l   l   o 177  \n
        150 145 154 154 157 177 012
0000007

177 is the ascii octal code for DEL, not Backspace. This may vary by system, though.

Upvotes: 2

RichieHindle
RichieHindle

Reputation: 281485

Hit Ctrl+V before hitting backspace. That tells the shell to treat the following keystroke literally, rather than interpreting its meaning.

Depending on how your terminal is set up, the backspace key might be interpreted as delete, so you might need to hit Ctrl+H instead of backspace to get a backspace character in your file.

Upvotes: 3

Related Questions