8 Sep
2025
8 Sep
'25
4:57 p.m.
On 9/8/25 04:23, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
POSIX requires that the shell read builtin not consume any bytes beyond the end-of-line character. For non-seekable files like pipes, this requirement can only be met by reading one byte at a time, which is very slow. Avoid this by reading the entire input into a temporary file and having sh read from the temporary file. Since regular files are seekable, sh can read many bytes and then seek back to the correct file position.
Slow enough to make a noticeable difference in the context of the whole script?
Don't know 🙂. It's just a known antipattern and I saw bash using a decent amount of CPU time. -- Sincerely, Demi Marie Obenour (she/her/hers)