minor: "read line" may read several lines if stdin is a tty
From:
Stephane Chazelas
Subject:
minor: "read line" may read several lines if stdin is a tty
Date:
Mon, 25 Aug 2014 21:24:16 +0100
User-agent:
Mutt/1.5.21 (2010-09-15)
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.
Probably not a big deal as one is unlikely to type
<Ctrl-V><Ctrl-J>. On the other end, when input is from the
terminal, there's not much point optimising so you might as well
read one byte at a time.
See also:
bash -c 'read a; echo "1: $a"; head -n 1; read b; echo "3: $b"'
If typing a<Ctrl-V><Ctrl-J>b<Return>c<Return>, you see:
1: a
c
3: b
Instead of:
1: a
b
3: c
It's probably a bigger concern though if reading from a serial
device (/dev/ttyS0) in raw mode for instance.
--
Stephane