[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Heredoc leading tab/space behaviour

From: Ing. Gerold Broser
Subject: Heredoc leading tab/space behaviour
Date: Fri, 24 Jun 2022 13:53:07 +0200 (CEST)


Configuration Information 1:

Machine: x86_64
OS: linux-gnu
Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.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 
-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


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 


---- Note ----
Unicode characters:
- blank (U+2423) for space (U+20)
- tab (U+2B73) + 7 spaces for Tab (U+9)
used for clarity in the following.


sed -f - heredoc-error.sh <<-SCRIPT
⭲       s/more/else/

$ . heredoc.sh
bash: warning: here-document at line 2 delimited by end-of-file (wanted 
sed: file - line 3: unknown command: `S'

$ . heredoc-ok.sh
sed -f - heredoc-ok.sh <<-SCRIPT
⭲       s/else/else/
⭲       SCRIPT


I think it'd be convenient if Heredoc supports indentation with spaces at the 
delimiter line, too.

And, BTW, there's a mixture of (leading) backtick (U+60) and (trailing) 
apostrophe (U+27) at `SCRIPT' and `S' in the error message.

Kind regards

Gerold 'Geri' Broser

reply via email to

[Prev in Thread] Current Thread [Next in Thread]