Date:        Mon, 1 Aug 2022 09:08:40 +0200
    From:        Harald Dunkel <harald.dun...@aixigo.com>
    Message-ID:  <0b0342b5-be15-ebc4-989f-a0cc9ec6c...@aixigo.com>

  | a colleague pointed me to a changed behavior of bash 5.1.4 in Debian 11.

The change is probably related to a change in the way bash implements
here documents (temp files vs pipes), but

  | Would you mind to take a look at this code?

It is nonsense.

  | Lines 4 to 7 are lost. How comes? Is this a problem of bash at all?

No, of the function.   The lines aren't "lost", they will have been read
by head - head only outputs the first N lines of the file (or stdin in this
case) to the output, but it will read in buffer sized chunks.

When input is seekable, it might (but is not required to) seek back to the
position in the input file where it stopped writing, but it cannot do that
when reading from a pipe - which is always possible in this example, even
if here docs weren't implemented as pipes, consider:

        cat file | insert data N

That wouldn't have worked on any version I suspect (and bash has nothing to
do with that at all).

If you want to insert data into the middle of a file, use sed, that is what
(well one of the things) it is designed to do.

kre


Reply via email to