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

Re: read string containing null



2021-10-21 14:08:41 +0100, Peter Stephenson:
[...]
> 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.
[...]

Yes, though sysread does only one read() of a fixed size (8KiB
be default), so you'd need to call it in a loop.

Other options are:

cmd | LC_ALL=C read -u0 -k999999999 var

Though it allocates as much memory.

And there's:

var=$(cmd; print .); var=${var%.}

To get the contents of a regular file into a variable, there's also

zmodload zsh/mapfile
var=$mapfile[path/to/file]

-- 
Stephane




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