mora mora - 6 months ago 24
Bash Question

How to decode null character, '\0', by base64 command in bash shell?

I would like to check my test code,

$ printf 'A\0B' | base64


the output was

QQBC


To check it, I decoded the coded value above by

$ printf 'A\0B' | base64 | base64 -d
$ printf "\n"


Then the output was

AB


The null character, '\0', is missing.

Is this right behavior or do I have a solution to keep the null character?

Thank you very much.

Answer

The null character, '\0', is missing.

It's there, but invisible. (\0 is just an input mechanism; it's not what the null character actually looks like.)

To confirm this, you can pipe the output of that command to less, which has a special way of depicting control characters.

Comments