0

Could someone please help me with an example Target of how to run two (or more) Unix commands using a Bash shell from within an Ant Target but without writing a new shell script.

I found an answer here How to run multiple Unix Commands in one time? which is great but recommends creating a shell script which I don't want to do.

The code I am using so far is like this, it works but I am wondering if there is a neater way of doing it - in one tag perhaps with the two commands separated by a ";" or perhaps using an < exec > tag rather than the < shellscript > shown.

<target name="dos2unixTidyUp"  depends="deleteTemp" if="isUnix"  >
    <shellscript shell="bash" dir="${my-app-bin.dir}" osfamily="unix" >
        dos2unix *.sh
    </shellscript>
    <echo>dos2Unix formatting completed</echo>
    <shellscript shell="bash" dir="${my-app-bin.dir}" osfamily="unix" >
        chmod +x *.sh
    </shellscript>
    <echo>chmod +x *.sh commanded completed</echo>
</target>

For your answers please provide an Example < target > answer in here !! < /target >

If its possible to separate commands using a ";" can the commands be on separate lines or do they have to be on the same line.

robbie70
  • 1,515
  • 4
  • 21
  • 30

2 Answers2

1

You can use :

$ echo "hello"; echo "there"

will run all commands, or

$ mkdir "xxx" && cd "xxx" || echo "mkdir fail, will not cd ..."

will run 'cd' only if 'mkdir' success. if not, 'echo' will run

chenchuk
  • 5,324
  • 4
  • 34
  • 41
0

Thank you for your answers they did help me. I have managed to modify my Target like so. Having both unix commands on one line separated by the ";" also worked. If someone wants to post an example using an < exec > then please do so - that would also be helpful and I will mark that as a second Answer.

<target name="unixShellTidyup"  depends="deleteTemp" if="isUnix"  >
     <shellscript shell="bash" dir="${my-app-bin.dir}" osfamily="unix" >
          dos2unix *.sh ;
          chmod +x *.sh
      </shellscript>
      <echo>unixShellTidyup completed</echo>
</target>
robbie70
  • 1,515
  • 4
  • 21
  • 30