This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Here-Document execution fails with extra space after closing delimiter

On 04/03/2013 03:02 PM, shawn kielty wrote:
> this script works: 
> #! /bin/bash
> tclsh << SCRIPT 
> puts "hello world" 


> while this script fails: 
> #! /bin/bash
> tclsh << SCRIPT 
> puts "hello world" 

Here-docs are particular.  The end token must appear verbatim, exactly
as the start token was parsed - but the parser strips off trailing
space, so it is looking for a line matching exactly 'SCRIPT', and your
'SCRIPT ' is not such a line.  The error message is correct.  This is
not a cygwin-specific problem.

> with the error:
> $ ./
> ./ line 5: warning: here-document at line 3 delimited by end-of-file (wanted `DEL')
> hello world
> invalid command name "DEL"

The bit about 'wanted `DEL'' and 'invalid command name "DEL"' tells me
that you aren't faithfully copying-and-pasting when typing up your
email.  When I try on Linux, I get:

$ bash -c 'cat << foo
> hi
> foo '
bash: line 2: warning: here-document at line 0 delimited by end-of-file
(wanted `foo')

where the message from bash mentions the spelling it is looking for, not
some arbitrary string `DEL'.

Other shells (I tried dash, mksh, ksh, and zsh) are a bit more
forgiving, but ALL of them treat a line that does not match the expected
terminator (because it has an erroneous trailing space) as part of the
here-doc contents - all bash is doing differently is warning you about
the issue before proceeding on anyways.

The _only_ thing that might make this cygwin-specific is if the
unintentional trailing whitespace in your script is due to you using
carriage returns in part, but not all, of your file, and even then, you
can tell bash to ignore carriage returns on cygwin (it's not on by
default for various reasons, but lots of people use that mode to
compensate for sloppy habits in editing files).

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]