Ant exec shell script - loses environment

I am trying to execute a shell script, as in Ant:

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

But when it runs the script, all references to environment variables, such as $ MY_VARIABLE, are returned as an empty string. How do I get around this? According to http://ant.apache.org/manual/Tasks/exec.html I believe the environment should be distributed. (I also understand that newenvironment defaults to false.)

Edit: I see an env element, but I see no way to pass the environment in bulk. Is there any way to do this?

+3
source share
2 answers

Did you export the variable? Subprocesses will not see the variable if you do not 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
+4
source

Uhm, bash ( ), bash .

<exec executable="script.sh" newenvironment="false" dir="./">
</exec>
0

Source: https://habr.com/ru/post/1718565/


All Articles