On 9/17/25 9:48 AM, Robert Elz wrote:

[email protected] said:
   | I'm not sure exactly what bash is doing here, but I'm guessing it has
   | something to do with switching the terminal from canonical mode to raw
   | mode...?

I don't look at bash code, but the NetBSD shell sets the "eol" char in
the terminal to the delimiter, so that a read will terminate when that
character is input.   My guess is that bash might do the same.

No. There are a couple of reasons. First, multibyte characters. Using your
scheme prohibits you from using a multibyte character as a delimiter (bash
doesn't do this now, but may in the future), and there are (still) locale
encodings that are (still) in use where the delimiter byte could be a
component of a valid multibyte character. The second reason is more
pragmatic: the -d code reuses an existing code path that already used
single-character reads (-n, -N).

If NetBSD doesn't ship with any non-UTF-8 encodings, you don't have to
worry about the first one too much, though I'm sure you could construct
a case where it would leave an incomplete multibyte character.

Chet

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

Reply via email to