[CentOS] HERE document in docker script file

Pete Biggs pete at biggs.org.uk
Tue Apr 30 08:25:39 UTC 2019


> > EOF: line 6: warning: here-document at line 0 delimited by end-of-file
> > (wanted `EOF')
> > 
> > This is the sample script I am testing in my docker file:
> > 
> > RUN bash -c "$(/bin/echo -e "cat << 'EOF' | tee -a /test.txt \
> >     \n<test> \
> >     \n  someting here \
> >     \n  something else here \
> >     \n</test>")" \
> > EOF
> > 
> > Can anyone see what is wrong in the above statement?
> > 
> > Thanks.
> > 
> > 
> > 
> The second EOF should be before  the part ")" \ and not after, because it
> has to represent the closure of the first one above....
> 
> So it should be something like this (I have put /tmp/test.txt as I tested
> as non root user that cannot write into /)
> 
> bash -c "$(/bin/echo -e "cat <<EOF | tee -a /tmp/test.txt \
> \n<test> \
> \n something here \
> \n</test>
> EOF
> ")"

It is also necessary to have the closing here document delimiter on a
line on its own, as you have done, but the OP hadn't. In all these
things it's often useful to remove the escaped new lines. The OPs
original command would been something like:

bash -c "$(/bin/echo -e "cat << 'EOF' | tee -a /test.txt \n<test> \n  someting here \n  something else here \n</test>")" EOF

It's obvious from this that the "EOF" isn't on a line on its own and is
in the wrong place compared to the parenthesis.

P.




More information about the CentOS mailing list