views:

2208

answers:

1

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/CoreTasks/exec.html I believe the environment should be propogated. (I also realize newenvironment defaults to false.) Thanks,

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

+2  A: 

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
bkail