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

Re: Help find Zsh' Bash `read -N1 -p "Put here " var



2023-08-22 18:42:02 +0100, Stephane Chazelas:
[...]
> with the caveat about NUL above. Actually, in bash, you'd
> probably be better of using:
> 
> LC_ALL=C read -rd '' -n1 var
> 
> That is read up to one byte from a NUL-delimited record. So read
> would return immediately upon the first byte received even if
> it's 0. Beware of the effect on the exit status though.
[...]

Sorry, should have been:

LC_ALL=C IFS= read -rd '' -n1 var

While bash's read doesn't do IFS processing with -N, it does
with -n, so you need to set IFS to the empty string for read
as otherwise it would strip any character in $IFS if input
before storing into $var.

May be worth mentioning the sysread builtin from the zsh/system
module which gives you more control when reading a fixed number
of bytes (see info zsh sysread).

-- 
Stephane




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