3 ms·
All kinds of binary data might have a NUL byte. E.g. if you want to write a NUL byte to a file in the shell, you might try something like echo -n $'\0' > n
by singron 7y ago
All kinds of binary data might have a NUL byte. E.g. if you want to write a NUL byte to a file in the shell, you might try something like
echo -n $'\0' > nul
This doesn't work for the reason stated in the article. The argument is instead interpreted as a string ended at the NUL byte and the file will be empty. BTW you can get around this with printf since it processes escape sequences internally.
printf '\0' > nul
- nneonneo 7y agoThere's also `echo -ne '\0'`, which works similarly (it tells echo to interpret the escape sequences).