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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With