* echo do not print NUL byte
@ 2016-01-20 21:38 Trek
2016-01-20 22:19 ` Eric Blake
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Trek @ 2016-01-20 21:38 UTC (permalink / raw)
To: dash
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 \n
with a shell that requires echo -e (ksh, bash, busybox, mksh):
$ sh -c 'echo -e \\0 | od -An -c'
\0 \n
with dash (XSI, no -e argument):
$ dash -c 'echo \\0 | od -An -c'
\n
where others characters are correctly printed:
$ dash -c 'echo \\0100 | od -An -c'
@ \n
with dash it only works with printf:
$ dash -c 'printf \\0\\n | od -An -c'
\0 \n
I 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!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: echo do not print NUL byte
2016-01-20 21:38 echo do not print NUL byte Trek
@ 2016-01-20 22:19 ` Eric Blake
2016-01-20 22:32 ` Harald van Dijk
2016-01-21 7:18 ` Bastian Bittorf
2 siblings, 0 replies; 5+ messages in thread
From: Eric Blake @ 2016-01-20 22:19 UTC (permalink / raw)
To: Trek, dash
[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]
On 01/20/2016 02:38 PM, Trek wrote:
> 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.
> 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.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: echo do not print NUL byte
2016-01-20 21:38 echo do not print NUL byte Trek
2016-01-20 22:19 ` Eric Blake
@ 2016-01-20 22:32 ` Harald van Dijk
2016-01-21 1:40 ` Trek
2016-01-21 7:18 ` Bastian Bittorf
2 siblings, 1 reply; 5+ messages in thread
From: Harald van Dijk @ 2016-01-20 22:32 UTC (permalink / raw)
To: Trek, dash
Hi,
On 20/01/2016 22:38, Trek wrote:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: echo do not print NUL byte
2016-01-20 22:32 ` Harald van Dijk
@ 2016-01-21 1:40 ` Trek
0 siblings, 0 replies; 5+ messages in thread
From: Trek @ 2016-01-21 1:40 UTC (permalink / raw)
To: Harald van Dijk; +Cc: dash
On Wed, 20 Jan 2016 23:32:11 +0100
Harald van Dijk <harald@gigawatt.nl> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: echo do not print NUL byte
2016-01-20 21:38 echo do not print NUL byte Trek
2016-01-20 22:19 ` Eric Blake
2016-01-20 22:32 ` Harald van Dijk
@ 2016-01-21 7:18 ` Bastian Bittorf
2 siblings, 0 replies; 5+ messages in thread
From: Bastian Bittorf @ 2016-01-21 7:18 UTC (permalink / raw)
To: Trek; +Cc: dash
* Trek <trek00@inbox.ru> [21.01.2016 07:06]:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-01-21 7:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-20 21:38 echo do not print NUL byte Trek
2016-01-20 22:19 ` Eric Blake
2016-01-20 22:32 ` Harald van Dijk
2016-01-21 1:40 ` Trek
2016-01-21 7:18 ` Bastian Bittorf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).