Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant exec shell script - loses environment

Tags:

shell

ant

I am trying to exec a shell script like so in Ant:

<exec executable="bash" newenvironment="false" dir="./">
  <arg value="script.sh">
</exec>

But when it executes the script, all references to environment variables such as $MY_VARIABLE come back as the empty string. How do I get around this? According to http://ant.apache.org/manual/Tasks/exec.html I believe the environment should be propogated. (I also realize newenvironment defaults to false.)

Edit: I see the env element, but I don't see a way to pass the environment in en masse. Is there a way to do that?

like image 657
PHeath Avatar asked Dec 05 '25 17:12

PHeath


1 Answers

Have you exported the variable? Sub-processes will not see the variable unless you export it:

$ cat a.xml
<project>
  <exec executable="bash" newenvironment="false" dir=".">
    <arg value="script.sh"/>
  </exec>
</project>
$ cat script.sh
#!/bin/sh
env
$ MY_VARIABLE=defined
$ ant -f a.xml | grep MY_VARIABLE
$ export MY_VARIABLE
$ ant -f a.xml | grep MY_VARIABLE
     [exec] MY_VARIABLE=defined
like image 166
Brett Kail Avatar answered Dec 07 '25 11:12

Brett Kail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!