Unable to use here-document delimited by EOF within phing XML

◇◆丶佛笑我妖孽 提交于 2019-12-25 09:15:27

问题


I have some commands to be run after switching to a different user. I need to do this in a build xml file.

Following is what I have done -

<exec command="sudo su auto_deploy &lt;&lt; EOF
echo 'Logged in user'
whoami
EOF" dir="${dir.scratchpad}" />

I have used XML escaping, i.e. &lt; for <.

However, I am getting the following error -

sh: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')

Related question - here-document gives 'unexpected end of file' error

Update

Note - I have not put any space after the starting EOF and before the ending EOF.

Update 1

Added bounty. Expecting an elaborate answer because I am unable to make much sense from the comments so far. Pardon my lack of knowledge.

Update 2

Just in case it was not clear, I am working on Phing, and the XML that I mentioned above is from the build xml file that Phing allows a user to write, to do deployment related stuff.

Update 3

As mentioned in the question referenced by @tripleee, I tried with this -

  <exec command="sudo su auto_deploy &lt;&lt; EOF${line.separator}echo 'Logged in user'${line.separator}whoami${line.separator}EOF" dir="${dir.scratchpad}" />

but it still throws the same error. Not sure what am I missing.


回答1:


I've never used phing before, but looking at the documentation it looks like there are a couple of ways to solve your problem. First, using the -verbose option it looks like your original solution might Just Work if you add an additional newline after the final EOF. That is, if I have this build.xml:

<?xml version="1.0"?>
<project name="chamilo" default="clean" basedir=".">
<target name="test">
<exec command="sudo -u deploy bash &lt;&lt;EOF${line.separator}echo Logged in user;whoami${line.separator}EOF" />
</target>
</project>

And I run phing -verbose test, I see:

     [exec] Executing command: sudo -u deploy bash <<EOF
echo Logged in user;whoami
EOF 2>&1
sh: line 2: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
     [exec] Logged in user
     [exec] deploy
     [exec] bash: line 2: EOF: command not found

Look at the final line of the generated script, which looks like:

EOF 2>&1

If I add an additional newline, like this:

<?xml version="1.0"?>
<project name="chamilo" default="clean" basedir=".">
<target name="test">
<exec command="sudo -u deploy bash &lt;&lt;EOF${line.separator}echo Logged in user;whoami${line.separator}EOF${line.separator}" />
</target>
</project>

Then it Just Works:

     [exec] Executing command: sudo -u deploy bash <<EOF
echo Logged in user;whoami
EOF
 2>&1
     [exec] Logged in user
     [exec] deploy


来源:https://stackoverflow.com/questions/39039416/unable-to-use-here-document-delimited-by-eof-within-phing-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!