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:00:15 +0900

2021年4月6日(火) 17:44 Marco Ippolito <maroloccio@gmail.com>:
> >     _read_timeout_buffer+=_read_timeout_c
>
> Suspected typo?: _read_timeout_buffer+=$_read_timeout_c
>
> >   done
> >   read "${@:2}" < "$_read_timeout_buffer"
>
> 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!

> > function read-timeout {
> >   local _read_timeout_buffer=
>
> This could omit the empty string assignment as in the statement below, 
> couldn't
> it?

Ah, yes (as far as the variable name `_read_timeout_buffer' is not
used outside the function). But I basically initialize this kind of
variables with an empty string because it can be affected by the
external variables. For example,

$ func() { local var; var+=a; var+=b; echo "$var"; }
$ func
ab   # <-- expected
$ var=blah func
blahab   # <-- unexpected
$ shopt -s localvar_inherit
$ var=foo
$ func
fooab # <-- unexpected

--
Koichi



reply via email to

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