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 << EOF
echo 'Logged in user'
whoami
EOF" dir="${dir.scratchpad}" />
I have used XML escaping, i.e. <
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 << 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.
sudo su auto_deploy <<-EOF
– Fostoriahere-document at line 0
as "I didn't get anything for input". Did you try removing the space, so you have...<EOF
? Even if that fixes it, you may get a new error message. I'm skeptical (but will be happy to learn otherwise) that<exec ...
can take a multiline input. Could youecho "echo 'user'; whoami" |sudo ...
instead? Good luck. – Schaub|sudo
there. – Waltersecho "xxx " | command
. But with thesudo su
in the way, it's likely that won't work. maybe<exec command="sudo su \"echo 'logged in';whoami\" | auto_deploy...
? Good luck. – Schaubsudo
, and so the terminatingEOF
is never found. – Salomeexec
element? It looks like that's the one which isn't handling newlines correctly. There is nothing in XML syntax specifically to define how exactly this should work; it's up to the tool to decide whether and if so how to process multi-line attributes. – Cindacindee<exec command="sudo su auto_deploy << 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. – Walters<exec command="sudo su auto_deploy << EOF
echo 'Logged in user etc'" etc="etc." />
? – Swot

after the startingEOF
and without any endingEOF
? – Walters

(the encoded newline character) in every place that you want to have newline characters in your attribute value. Just like you use<
(the encoded left angle bracket character) in every place where you want to have a<
in your attibute value. – Swot