Question

The shell script is erroring with

line 6: warning: here-document at line 2 delimited by end-of-file (wanted `_EOF_')

Here's the code:

#!/bin/bash
    cat <<- _EOF_  
        test:  
        1. test  
        0. test test   
    _EOF_

But it is right.

#!/bin/bash
cat <<- _EOF_  
    test:  
    1. test  
    0. test test   
_EOF_  
Was it helpful?

Solution

From the Bash manual:

If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.

That is, it will fail if you have indented these lines with spaces, rather than tabs.

Another invisible problem is that the termination word must appear on the line, alone, with nothing around it. The only exception is leading tabs, if you use <<- instead of <<. So, a trailing space on the _EOF_ line would do this.

By the way, testing does show that Bash will tolerate a space between <<- and the termination word, but it isn't shown as allowed in the Bash manual. This might be a portability problem.

OTHER TIPS

The - option to a here document <<- suppresses leading tabs in the body of the document but not spaces.

So replace space with tabs then your warning messages will gone..

Example :

if true;
then
        cat <<- _EOF_
            test:
            1. test
            0. test test
        _EOF_

fi

Reference Link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top