Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: read string containing null

Yes, I want to read the whole stdin in a single operation, so the -d was there to disable stopping at newline
It seem that instead made read stop at null bytes
I worked around this limitation with:

xx=$(echo -e - a$'\000'b; echo .); xx=${xx[1,-2]}; echo -n - $xx

but I will try also your suggestion, thanks

Pier Paolo Grassi

Il giorno gio 21 ott 2021 alle ore 15:08 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> ha scritto:
> On 21 October 2021 at 13:35 Pier Paolo Grassi <pierpaolog@xxxxxxxxx> wrote:
> Hello, I just found out:
> echo -e - a$'\000'b | IFS='' builtin read -r -d '' xx; echo -n - $xx
> result is "a"
> is it possible for builtin read not to stop an null bytes? I found nothing
> in documentation.
> thanks

I think -d '' is telling it to treat NULL bytes as a delimiter.  Take that out.

If you're not trying to read a line, don't use read.  If you "zmodload zsh/system"
there's a sysread command which is more useful for lower level operations.


Messages sorted by: Reverse Date, Date, Thread, Author