zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Budi <budikusasi@gmail.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: Help find Zsh' Bash `read -N1 -p "Put here " var
Date: Tue, 22 Aug 2023 20:03:30 +0100	[thread overview]
Message-ID: <20230822190330.qytgyr3oadewezvp@chazelas.org> (raw)
In-Reply-To: <20230822174202.adcxbpipov7vsmc2@chazelas.org>

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


      parent reply	other threads:[~2023-08-22 19:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 12:23 Budi
2023-08-22 12:44 ` Pier Paolo Grassi
2023-08-22 14:19   ` Budi
2023-08-22 14:30     ` Peter Stephenson
2023-08-22 15:21 ` zeurkous
2023-08-22 15:34   ` Ellenor Bjornsdottir
2023-08-22 15:39     ` zeurkous
2023-08-22 17:01     ` Andreas Kusalananda Kähäri
2023-08-22 17:42 ` Stephane Chazelas
2023-08-22 19:01   ` Bart Schaefer
2023-08-22 19:03   ` Stephane Chazelas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230822190330.qytgyr3oadewezvp@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=budikusasi@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).