mora mora - 1 year ago 66
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


To check it, I decoded the coded value above by

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

Then the output was


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 Source

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.