Josh
Josh

Reputation: 8026

How do I generate ASCII codes 2 and 3 in a Bash command line?

If I press Ctrl+B that ought to give me ASCII code 2, but Ctrl+C is going to be interpreted as a Break.

So I figure I've got to redirect a file in. How do I get these characters into a file?

Upvotes: 3

Views: 3791

Answers (3)

Steve M
Steve M

Reputation: 10573

perl -e 'print "\xFF"'

where FF is the hex code of the ACSII code you want to print. So for ACSII code 2, it would be \x02.

Upvotes: 2

Josh
Josh

Reputation: 8026

Ctrl-V escapes the next keystoke. That's how you can get a Ctrl-C out: Ctrl-V Ctrl-C

Upvotes: 10

Daniel Fone
Daniel Fone

Reputation: 2905

echo $'\002\003' > ./myfile

Upvotes: 6

Related Questions