bug-bash
[Top][All Lists]
Advanced

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

Re: minor: "read line" may read several lines if stdin is a tty


From: Chet Ramey
Subject: Re: minor: "read line" may read several lines if stdin is a tty
Date: Wed, 27 Aug 2014 08:10:01 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 8/25/14, 4:24 PM, Stephane Chazelas wrote:
> If you run (here testing on Linux):
> 
>   bash -c 'read a; echo "<$a>"; tr b c'
> 
> And enter aaa<Ctrl-V><Ctrl-J>bbb<Return>
> 
> You see "<aaa>", but not "ccc". That's because "read" reads up
> to 128 bytes of data in one read(2) invocation instead of
> reading one byte at a time like on other types on non-seekable
> files.

While this is true, it's not complete.  Bash relies on the terminal
driver returning newline-delimited lines when reading from the
terminal.  If you try to fool it, you can probably succeed.

Chet

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



reply via email to

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