bug-bash
[Top][All Lists]
Advanced

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

Re: read -N 1 </dev/zero runs forever


From: Chet Ramey
Subject: Re: read -N 1 </dev/zero runs forever
Date: Mon, 4 Feb 2019 15:14:41 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.0

On 2/4/19 11:45 AM, John Passaro wrote:

> Bash Version: 4.4
> Patch Level: 23
> Release Status: release
> 
> Description:
>       The `read` builtin skips null characters and does not count
>       them toward the limit specified by -n/-N. This leads to
>       surprising behavior with /dev/zero: read -N 1 </dev/zero
>       never terminates!
> 
>       This is obviously a corner case but it violates what ought
>       to be a safe user assumption that specifying -N prevents
>       read from running for too long.
> 
> Repeat-By:
>       $ tr \\0 a </dev/zero | read -N # terminates immediately
>       $ tr \\0 \\0 </dev/zero | read -N # runs forever
> 
>       or in the absence of /dev/zero:
>       $ while true ; do echo -n a ; done | read -N 1 # terminates
>       $ while true ; do echo -n a ; done | tr a \\0 | read -N 1 # runs forever
> 
> Fix:
>       I propose to count nulls toward nchars.

Thanks for the proposal. I'll keep it in mind for a future version.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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