echo do not print NUL byte
there is no way to print the NUL byte with the echo utility
with an XSI shell (mksh, posh, yash):
$ sh -c 'echo \\0 | od -An -c'
\0 \nwith a shell that requires echo -e (ksh, bash, busybox, mksh):
$ sh -c 'echo -e \\0 | od -An -c'
\0 \nwith dash (XSI, no -e argument):
$ dash -c 'echo \\0 | od -An -c'
\nwhere others characters are correctly printed:
$ dash -c 'echo \\0100 | od -An -c'
@ \nwith dash it only works with printf:
$ dash -c 'printf \\0\\n | od -An -c'
\0 \nI discovered this bug developing a small shell library, where you can find an use case in the n_bytes_encode function of the lib/bytes.sh file included in http://www.trek.eu.org/devel/naive/naive-0.0.2.tar.gz
c-ya!
Quoted 1 line · Trek
there is no way to print the NUL byte with the echo utility
POSIX says you should use 'printf', not 'echo', if you expect to use any \ in the arguments. That said, the man page says:
echo [-n] args...
...
\0digits
Output the character whose value is given by zero to
three
octal digits. If there are zero digits, a nul character is output.
Quoted 4 lines
with dash (XSI, no -e argument):
$ dash -c 'echo \\0 | od -An -c' \n
So this is behavior in disagreement with the documentation, so you definitely have discovered a bug. Of course, since POSIX already says the use of \ is implementation-defined if XSI is not in force, and dash doesn't necessarily strive for full XSI compliance, it might be easier to patch the docs than to output a NUL byte.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Hi,
Quoted 6 lines · Trek
there is no way to print the NUL byte with the echo utility
with dash (XSI, no -e argument):
$ dash -c 'echo \\0 | od -An -c' \n
This is https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=379227, which did get fixed already, but it was after 0.5.8. That should mean it will be in the next release of dash, but you can check out the sources from Git if you want to see it now.
Cheers,
Harald van Dijk
Quoted 2 lines · On Wed, 20 Jan 2016 23:32:11 +0100 Harald van Dijk <[email protected]> wrote:
This is https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=379227,
which did get fixed already, but it was after 0.5.8.
happy to see that it is already fixed and sorry for double reporting
Quoted 1 line · Trek
included in http://www.trek.eu.org/devel/naive/naive-0.0.2.tar.gz
interesting! can you switch to git or another CVS?
bye, bastian