help-bash
[Top][All Lists]
Advanced

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

Re: terminate read after not receiving additional input for some time


From: Koichi Murase
Subject: Re: terminate read after not receiving additional input for some time
Date: Tue, 6 Apr 2021 18:08:55 +0900

2021年4月6日(火) 18:00 Koichi Murase <myoga.murase@gmail.com>:
> 2021年4月6日(火) 17:44 Marco Ippolito <maroloccio@gmail.com>:
> > Suspected typo?: _read_timeout_buffer+=$_read_timeout_c
> > [...]
> > Suspected typo?: read "${@:2}" <<< "$_read_timeout_buffer"
>
> Oh, sorry. You're completely right. I have tested locally and fixed
> them, but forgot to update the email body. Thank you for pointing it
> out!

P.S. so this is the fixed version:

function read-timeout {
  local _read_timeout_buffer=
  local _read_timeout_c
  while IFS= read -t "$1" -r -n 1 _read_timeout_c || [[ $_read_timeout_c ]]; do
    _read_timeout_buffer+=$_read_timeout_c
  done
  read "${@:2}" <<< "$_read_timeout_buffer"
}
read-timeout 2 -r x < <(echo -n a; sleep 1; echo -n b; sleep 1; echo
-n c; sleep 1; echo -n d)
echo "$? [$x]"

--
Koichi



reply via email to

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