Hi Gerold, On Fri, 24 Jun 2022 13:53:07 +0200 (CEST) "Ing. Gerold Broser" via Bug reports for the GNU Bourne Again SHell <bug-bash@gnu.org> wrote:
> Hello, > > Configuration Information 1: > > Machine: x86_64 > OS: linux-gnu > Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.3 > -L/home/abuild/rpmbuild/BUILD/bash-4.3/../readline-6.3 > Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' > -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-suse-linux-gnu' > -DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL > -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -fmessage-length=0 > -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 > -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g > -D_GNU_SOURCE -DRECYCLES_PIDS -Wall -g -Wuninitialized -Wextra > -Wno-unprototyped-calls -Wno-switch-enum -Wno-unused-variable > -Wno-unused-parameter -Wno-parentheses -ftree-loop-linear -pipe -DBNC382214=0 > -DIMPORT_FUNCTIONS_DEF=0 -fprofile-use > uname output: Linux <...host name...> 4.12.14-122.116-default #1 SMP Tue Apr > 5 13:16:39 UTC 2022 (b42b08b) x86_64 x86_64 x86_64 GNU/Linux > Machine Type: x86_64-suse-linux-gnu > > Bash Version: 4.3 > Patch Level: 48 > Release Status: release > > Configuration Information 2 (Win 10 Enterprise, Git Bash v2.34.1): > > Machine: x86_64 > OS: msys > Compiler: gcc > Compilation CFLAGS: -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='x86_64' > -DCONF_OSTYPE='msys' -DCONF_MACHTYPE='x86_64-pc-msys' -DCONF_VENDOR='pc' > -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H > -DRECYCLES_PIDS -I. -I. -I./include -I./lib -DWORDEXP_OPTION > -Wno-discarded-qualifiers -march=x86-64 -mtune=generic -O2 -pipe > -Wno-parentheses -Wno-format-security -D_STATIC_BUILD -g > uname output: MINGW64_NT-10.0-19042 <...host name...> 3.1.7-340.x86_64 > 2021-10-12 16:29 UTC x86_64 Msys > Machine Type: x86_64-pc-msys > > Bash Version: 4.4 > Patch Level: 23 > Release Status: release > > > Description: > > The Bash Reference Manual says about Heredoc's redirection operator '<<-': > > "If the redirection operator is ‘<<-’, then all leading tab characters are > stripped from input lines and the line containing delimiter." > – https://www.gnu.org/software/bash/manual/bash.html#Here-Documents > > This is only half true since apparently also leading spaces are stripped from > input lines (while they are not from the delimiter line, and lead to an error > there). They're not, though. $ printf '%s\n' 'cat <<-EOF' $'\x20\x20foo' $'\t\tbar' EOF | bash | od -a 0000000 sp sp f o o nl b a r nl 0000012 Note that the two space characters preceding foo are preserved, whereas the two leading tab characters preceding bar are not. > > > Repeat-By: > > ---- Note ---- > Unicode characters: > - blank (U+2423) for space (U+20) > and > - tab (U+2B73) + 7 spaces for Tab (U+9) > used for clarity in the following. > -------------- > > heredoc-error.sh: > > #!/bin/bash > sed -f - heredoc-error.sh <<-SCRIPT > ␣␣s/something/else/ > ⭲ s/more/else/ > ␣␣SCRIPT > > $ . heredoc.sh > bash: warning: here-document at line 2 delimited by end-of-file (wanted > `SCRIPT') > sed: file - line 3: unknown command: `S' > > > $ . heredoc-ok.sh > #!/bin/bash > sed -f - heredoc-ok.sh <<-SCRIPT > ␣␣s/else/else/ > ⭲ s/else/else/ > ⭲ SCRIPT > > > Fix: > > I think it'd be convenient if Heredoc supports indentation with spaces at the > delimiter line, too. One issue with this proposal is that it would violate the rules of the Shell Command Language, per https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04. -- Kerin Millar