GNU bug report logs -
#8103
tac RFE: accept -z, --zero-terminated option
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On 02/25/2011 01:09 PM, Jim Meyering wrote:
>> Actually the shell does. $'\0' and '' are indistinguishable once passed
>> as argument.
>
> I thought so, too. Then I tried this:
>
> $ zsh -c "printf \$'\0'|wc -c"
> 1
> $ bash -c "printf \$'\0'|wc -c"
> 0
>
> The former prints a NUL byte.
> The latter prints nothing.
>
> So it depends on your shell.
zsh does some magic to preserve NUL bytes _when passed as arguments to
shell builtins_. In this case, printf is a zsh shell builtin,
therefore, zsh's $'\0' is able to preserve the fact that you passed in a
NUL byte, then printf outputs that NUL byte again, such that wc sees it
on stdin.
But zsh is special in that regards, and it violates the upcoming POSIX
wording that will be standardized regarding $'' behavior (which means
zsh will have to add yet another shell option soon, if it hasn't
already, to choose between posix and zsh behavior regarding NUL):
http://austingroupbugs.net/view.php?id=249
If a \xXX or \XXX escape sequence yields a byte whose value
is 0, that byte and any following regular characters and
escape sequences up to the terminating unescaped single-quote
shall be evaluated and discarded.
Bash, on the other hand, strips NUL bytes everywhere. And zsh _can't_
preserve NUL bytes to non-builtins.
[As a side note, printf '\0' portably prints a NUL byte, but that's
because you're passing two bytes on input which get interpreted as an
escape sequence, and not passing a literal NUL byte as in zsh printf $'\0']
--
Eric Blake eblake <at> redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 6 years and 252 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.