On 5/2/21 9:51 AM, Koichi Murase wrote:
Maybe I'm asking a stupid question, but, as in the subject, why does the builtin "mapfile -d delim" use unbuffered read when delim != '\n'?
It's the shell being careful in the general case. You need to guarantee behavior in all of the cases where read(2) will not return until it sees a newline.
Can we use buffered read for seekable file descriptors the same as the `delim == '\n'' case?
You should be able to, yes.
This treatment of `mapfile' for "delim != '\n'" exists since the mapfile delimiter is first introduced by commit 25a0eacfe "commit bash-20140625 snapshot". Would it be a problem to change to the buffered read also for non-LF delimiters? If we could remove the above two lines (i.e., if (delim != '\n') unbuffered_read = 1;), I'd be very happy...
Try it out and see. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/