Hi folks,

a colleague pointed me to a changed behavior of bash 5.1.4 in Debian 11.
Would you mind to take a look at this code?

----
#! /bin/bash
# set -x

insert()
{
   local data="$1"
   local lineNumber="$2"

   head -n "$lineNumber"

   echo '   <!-- BEGIN inserted by '"$( basename "$0" )"' -->'
   cat <<< "$data"
   echo '   <!-- END inserted by '"$( basename "$0" )"' -->'

   cat
}

text="this is line one
this is line two
this is line three
this is line four
this is line five
this is line six
this is line seven"

output="$( insert "Hello" 3 <<< "${text}" )"
echo "$output"
----


On bash 5.0.3 (Debian 10) it shows

----
this is line one
this is line two
this is line three
   <!-- BEGIN inserted by works_on_deb10_but_not_deb11 -->
Hello
   <!-- END inserted by works_on_deb10_but_not_deb11 -->
this is line four
this is line five
this is line six
this is line seven
----


On bash 5.1.4 (Debian 11) and 5.1.6 (openBSD 7.1) I get
----
this is line one
this is line two
this is line three
   <!-- BEGIN inserted by works_on_deb10_but_not_deb11 -->
Hello
   <!-- END inserted by works_on_deb10_but_not_deb11 -->
----


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


Every insightful comment is highly appreciated

Harri

Reply via email to