bug-bash
[Top][All Lists]
Advanced

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

Re: ``read -N n -t timeout'' saves partial input only when EOF is seen?


From: isabella parakiss
Subject: Re: ``read -N n -t timeout'' saves partial input only when EOF is seen?
Date: Thu, 24 Nov 2016 18:49:46 +0100

On 11/24/16, Chet Ramey <address@hidden> wrote:
> On 11/24/16 2:57 AM, Clark Wang wrote:
>> See following example:
>>
>> # echo $BASH_VERSION
>> 4.4.5(2)-release
>> # ( printf 12345 ) | ( read -t 1 -N 10 v; echo "<$v>" )
>> <12345>
>> # ( printf 12345; sleep 2 ) | ( read -t 1 -N 10 v; echo "<$v>" )
>> <>
>> #
>>
>> The second "read" did not save "12345" to "v". Is this a bug?
>
> No, it's a race condition.  It depends on when the kernel schedules
> each process in the pipeline: if the read gets scheduled and times out
> before the subshell that runs the printf/sleep combination runs and
> writes something to the pipe, you won't get any output.  On Mac OS X,
> for example, you get <12345>.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    address@hidden
> http://cnswww.cns.cwru.edu/~chet/
>
>

that's not true https://gist.github.com/fa4efd90376ff2714901e4429fdee734
read successfully reads the data, but then it's discarded by bash
i don't know how/why it works on your mac, but it sure looks like a bug

---
xoxo iza



reply via email to

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