Bug 25422 - here documents confused by trailing spaces
Summary: here documents confused by trailing spaces
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: bash
Version: 6.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Bernhard Rosenkraenzer
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-01-31 21:36 UTC by John Hardin
Modified: 2007-04-18 16:31 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2001-02-01 18:45:16 UTC
Embargoed:


Attachments (Terms of Use)

Description John Hardin 2001-01-31 21:36:58 UTC
If a here document is defined with spaces after the delimiter names, and
the number of spaces don't match, the processing of the here document is
incorrect: bash will ignore the terminating delimiter completely.

Example:

(assume "set list" mode so trailing blanks are visible)

   program <<-EOF     $
        fnord         $
        fnord         $
   EOF                $
                      $
   other-program      $

...will echo:

   fnord
   fnord
   EOF

   other-program

bash should ignore trailing spaces completely when checking the delimiters.

Comment 1 Bernhard Rosenkraenzer 2001-02-01 16:09:39 UTC
POSIX demands this behavior, so it's not a bug.

Comment 2 John Hardin 2001-02-01 18:45:12 UTC
{boggle} You've *got* to be kidding...

Unfortunately I'm not an IEEE member or subscriber, so I can't reference the
posix 1003.2 standards document directly.

However, quoting from
http://www.opengroup.org/onlinepubs/7908799/xcu/chap2.html#tag_001_007_004

"The here-document is treated as a single word that begins after the next
newline character and continues until there is a line containing only the
delimiter, _with no trailing blank characters._" (my emphasis added)

Granted, that may be a quote from an implementation-dependent feature, but given
the documentation for here-document redirection everywhere I've seen it:

    <<[-]word
       here-document
    delimiter

...since when has a token ("word" is "a token that is not an operator") *ever*
included whitespace *unless it was explicitly quoted*? It's not treated that way
elsewhere, is it?

I could see the objection if the script was:

   command << "fnord   "

or

   command << fnord\ \ \ \ 

but it's not.



Comment 3 John Hardin 2001-02-01 18:56:34 UTC
Oops. Rereading what I quoted makes the behavior correct. Don't I feel dumb.


Note You need to log in before you can comment on or make changes to this bug.