Reputation: 1167
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?
Upvotes: 3
Views: 13299
Reputation: 14115
Uhm, that executes a new bash shell (with whatever config and new environment are defined for your active user) and then the bash shell takes the arguments and executes.
Might try the following to execute in the current shell environment
<exec executable="script.sh" newenvironment="false" dir="./">
</exec>
Upvotes: 0
Reputation: 33946
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
Upvotes: 4