3 ms·
Data containing null bytes is not text. I like to think of bash / sh as just a job control system. It enables you to setup process pipelines. Everything is jus
by jstimpfle 11y ago
Data containing null bytes is not text.
I like to think of bash / sh as just a job control system. It enables you to setup process pipelines. Everything is just processes and files (streams). Variables only serve as programs arguments. Since program arguments are also null terminated, variables containing null bytes just make no sense.
(Of course it gets dirty as soon as you feed the output of a job into a variable, for example. I think that isn't even defined by POSIX for non-text streams).
- chongli 11y agoFeeding the output of a job into a variable is a common enough task. One example I worked on recently was to use the results of one find(1) command as an array of arguments to another. Perhaps this was a very ugly way of comparing two directories, but it worked. This is why it surprised me when I realized (without having thought about it) that variables can't contain null bytes. It made my quick id3 tag parsing script a bit trickier to write, since I could no longer just use read(1P).