Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: read string containing null
- X-seq: zsh-users 27261
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Cc: Pier Paolo Grassi <pierpaolog@xxxxxxxxx>, Zsh-Users List <zsh-users@xxxxxxx>
- Subject: Re: read string containing null
- Date: Fri, 22 Oct 2021 10:05:18 +0100
- Archived-at: <https://zsh.org/users/27261>
- In-reply-to: <899710302.733700.1634821721465@mail2.virginmedia.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>, Pier Paolo Grassi <pierpaolog@xxxxxxxxx>, Zsh-Users List <zsh-users@xxxxxxx>
- References: <CAP+y1xC9243rukfuZ9m64PMrZJD4O3eP-cu3s9noqXnFak7=KQ@mail.gmail.com> <899710302.733700.1634821721465@mail2.virginmedia.com>
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