-1
 unset files;
 git --no-pager diff --name-only HEAD HEAD~10 -- '*.php' |
 while IFS= read -r filename; do
     if [[ -f $filename ]]; then
         files+="./$filename,"
     fi
 done

 files="${files%,}" | phpmd "$files" text codesize

This in command line work perfectly. But then I define it in Ant build script like so:

<target name="phpmd"
        description="Perform project mess detection using PHPMD creating a log file for the continuous integration server">
    <exec executable="bash" failonerror="true" >
        <arg value="-c" />
        <arg value="unset files; git --no-pager diff --name-only HEAD HEAD~10 -- '*.php' |  while IFS= read -r filename; do if [[ -f $$filename ]]; then files+=&quot;./$$filename,&quot;; fi; done; files=&quot;$${files%,}&quot; | phpmd &quot;$$files&quot; text codesize" />
    </exec>
</target>

It doesnt work... Maybe someone will know whats the problem?

Saucier
  • 4,200
  • 1
  • 25
  • 46
Aurimas Niekis
  • 227
  • 1
  • 14
  • Open a new terminal, make sure you're running bash and not zsh/ksh, and then copy-paste the command. Does it still work perfectly? – that other guy Mar 17 '14 at 20:20
  • Oh yeah... It doesn't work in bash... Maybe you know why? – Aurimas Niekis Mar 17 '14 at 20:33
  • Wouldn't it be better and raise the maintainability to wrap your bash code into a script and call that script from your ant build script? – Saucier Mar 17 '14 at 20:49
  • @AurimasNiekis It's primarily due to modifying `$files` in a subshell ([shellcheck](http://www.shellcheck.net) points this out). You can [rewrite it to avoid the subshell](http://stackoverflow.com/questions/13726764/bash-script-while-loop-subshell-dilemma). – that other guy Mar 17 '14 at 21:21

1 Answers1

0

Have you tried using instead of for something that is more than just a single arguement.

For example:

<arg line="unset files; git --no-pager diff --name-only HEAD HEAD~10 -- '*.php' |  while IFS= read -r filename; do if [[ -f $$filename ]]; then files+=&quot;./$$filename,&quot;; fi; done; files=&quot;$${files%,}&quot; | phpmd &quot;$$files&quot; text codesize" />
mikemil
  • 1,213
  • 10
  • 21