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.

1
  • Just use <exec> task and separating two commands by ';' is the way to go Commented Aug 30, 2016 at 17:39

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.