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


          • ... Chet Ramey
          • ... Martin D Kealey
          • ... Chet Ramey
          • ... Carl Edquist
          • ... Martin D Kealey
          • ... Carl Edquist via Bug reports for the GNU Bourne Again SHell
          • ... Martin D Kealey
          • ... Carl Edquist via Bug reports for the GNU Bourne Again SHell
          • ... Zachary Santer
          • ... Martin D Kealey
          • ... Carl Edquist
  • Re: Examples o... Carl Edquist
    • Re: Examp... Martin D Kealey
      • Re: E... Chet Ramey
        • R... Zachary Santer
          • ... Chet Ramey
        • R... Carl Edquist
          • ... Chet Ramey
          • ... Zachary Santer
          • ... Chet Ramey
          • ... Carl Edquist via Bug reports for the GNU Bourne Again SHell

Reply via email to