bug-bash
[Top][All Lists]
Advanced

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

Re: "here document" causing failures. Implementation is inconsistent and


From: Andreas Kähäri
Subject: Re: "here document" causing failures. Implementation is inconsistent and not documented.
Date: Wed, 11 Oct 2023 05:13:23 +0200

On Wed, Oct 11, 2023 at 11:56:42AM +1100, Jim McD wrote:
> Bug:
> Trailing white space after the delimiting tag cause the here document to
> fail with an error like
> /./<script_name>: line <line_number>: warning: here-document at line
> <line_number> delimited by end-of-file (wanted `msg_end')Trailing white
> space/
> 
> Trailing white space after the start of the here statement is ignored.
> 
> This doesn't appear to be documented anywhere. All the material I have seen
> on here documents I've seen so far never mention the requirement that the
> tag a the end must be free of any trailing white space.
> 
> _Inconsistency _: If white space after the start of the here statement is
> permitted and ignored then it should be the same with a tag terminating the
> here statement.
> 
> Test script
> _______________________________________
> #/usr/bin/bash
> cat << msg_end

Here, "msg_end" is a word in the shell script.  It is not initiating the
here-document *at that instance*.  The here-document starts on the next
line.  The here-document is terminated by the occurence of the "msg_end"
word on a line by itself.

Consider also

        cat << msg_end | mailx -s "Test" user@example.com
        my message
        goes here
        msg_end

This would be impossible if the shell interpreted the first instance of
"msg_end" as anything other than an ordinary word in the script.

I'm using the word "word" loosely here.  I'm not a grammar expert, but
I might mean "token".

> 
>  Bash version
>  $(bash --version)
> 
> msg_end
> _______________________________________
> > *# This fails*
> *> cat -A test_here*
> #/usr/bin/bash$
> cat << msg_end       $
> $
>  Bash version$
>  $(bash --version)$
>   $
> msg_end $
> >
> > *# This works*
> *> cat -A test_here*
> #/usr/bin/bash$
> cat << msg_end       $
> $
>  Bash version$
>  $(bash --version)$
>   $
> msg_end$
> >
> _____________________________________
> Tested on these, all virtual machines excdept MSYS2 which runs alongside MS
> Win10. MS WSL2 is a virtual machine.
> Output is from bash --version and uname -a commands.
> 
> Zorin Linux -
> GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
> Linux XXXX 5.15.0-78-generic #85~20.04.1-Ubuntu SMP Mon Jul 17 09:42:39 UTC
> 2023 x86_64 x86_64 x86_64 GNU/Linux
> 
> MS Windows WSL2 (Ubuntu)
> GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
> Linux XXXX 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC
> 2023 x86_64 x86_64 x86_64 GNU/Linux
> 
> MS Windows MSYS2 (derived from Cygwin)
> GNU bash, version 5.2.15(1)-release (x86_64-pc-msys)
> MSYS_NT-10.0-19045 bob 3.4.6.x86_64 2023-02-15 18:03 UTC x86_64 Msys
> 
> Oracle on ARM
> GNU bash, version 5.1.16(1)-release (aarch64-unknown-linux-gnu)
> Linux ub01 5.15.0-1034-oracle #40-Ubuntu SMP Wed Apr 19 16:10:04 UTC 2023
> aarch64 aarch64 aarch64 GNU/Linux

-- 
Andreas (Kusalananda) Kähäri
Uppsala, Sweden

.



reply via email to

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