[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf "%q" and $'...'

From: Maarten Billemont
Subject: Re: printf "%q" and $'...'
Date: Wed, 25 Nov 2009 15:05:27 +0100

You can "output" $'\x00' just fine:

$ printf '\0'

Note that -d $'\x00' is the same thing as -d '', for the reason I mentioned 
earlier.  The argument to the -d option that "read" takes is a C-string.  
Understand the difference between *strings* and *streams*.  A stream (standard 
output of printf '\0' or find . -print0) can contain any byte.  A C-string can 
not contain NUL bytes.  If you want strings with NUL bytes, you need 

You can *not*, however, output a NUL byte by using $'\x00' as an argument.  
Because arguments can't contain NUL bytes (they are C-strings).  So outputting 
NUL a byte with this will *fail*:

$ echo $'\x00'

This will *also* fail:

$ printf $'\x00'

The first example I gave doesn't fail because the argument is not a NUL byte 
(empty), it is a backslash followed by a zero.  printf sees this argument and 
understands you want it to expand that into a NUL byte, then emits it on its 
output STREAM.

On 25 Nov 2009, at 14:35, Antonio Macchi wrote:

> it sounds strange, beacuse
> $ find . -print0 | while read -d $'\x00'; do touch "$REPLY"; done
> works fine.
> but if I try to "output" $'\x00', I can't.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]