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


Reply via email to