On Wed, 17 Apr 2024, Chet Ramey wrote:
On 4/16/24 2:46 AM, Carl Edquist wrote:
But the shell is pretty slow when you ask it to shovel data around like
this. The 'read' builtin, for instance, cautiously does read(2) calls
of a single byte at a time.
It has to do it that way to find the delimiter on a non-seekable file
descriptor, since it has to leave everything it didn't consume available
on stdin.
Understood, and I wouldn't have it any other way. It's entirely
appropriate for reading relatively small amounts of data into shell
variables. I'm just saying for copying or filtering a substantial amount
of data, it's 1000x better to use a suitable external command instead.
It makes me cringe a bit and sigh when I see people put something like
while read X; do echo "$X"; done
in a script, because they somehow imagine it to be more efficient than
simply running "cat" .
Carl