Schala Walls
Schala Walls

Reputation: 23

BASH/Readline Verbatim Null Character

I'm trying to understand exactly who among the set of TTY, kernel, line discipline, and shell actually deals with any given part of my input. In particular, I've been working through this article:

The TTY demystified

My question: if I want to have the actual delete character show up in BASH, I can use ^V to make it verbatim. E.g. I can use Ctrl+V then Ctrl+H to have a backspace character. Pretty neat!

echo '3^H'
3

My question is this: if I'm in something that reads in canonical mode (I believe cat does this) I can put a null character in there by doing Ctrl+V then Ctrl+2 (basically Ctrl+@, which is the caret notation for the null character).

BASH won't allow me to have a verbatim null character on one of its lines, though, and it looks like python and other readline programs won't either.

Does anybody know why this is, or a general-purpose workaround?

Upvotes: 0

Views: 316

Answers (1)

tripleee
tripleee

Reputation: 189337

The C library uses a literal null as a string terminator, so anything using that is unable to represent strings containing literal nulls.

Programs which need to support literal nulls define their own string data type.

Upvotes: 1

Related Questions