bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CORRECTED: Bug in the read command


From: pourko
Subject: Re: CORRECTED: Bug in the read command
Date: Mon, 22 Sep 2025 18:28:03 +0200 (CEST)

On Mon, 22 Sep 2025 09:27:17 -0400 Chet Ramey wrote:
> > If we add to each of them the `-d ""' option, then:
> > 
> > `read -d "" -t $nonzero' will slurp in all outstanding keys, regardless of
> > whether or not the RETURN key has been pressed.
> 
> OK, I'll bite. There's no portable way to determine `all' here, so you are
> left to poll/select with a zero timeout to see if there is input available,
> then do single-character reads until the select indicates there's no more
> pending input. You can do this from the shell level if you like.
> 
> while read -t 0; do
>         read -N 1 v
>         var+=v
> done

No, your snippet won't detect anything if keys have been typed in but the
RETURN key has no been pressed yet.

Which is why we add the -d "" option to each of the two possible scenarios:

RESULTS:

A) read -t 1 -d ""
This one slurps in everything that's there regardless of RETURN key.

B) read -t 0 -d ""
This one still leaves keys behind, those that have not been followed by RETURN.

It is B that bothers me.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]