Ayush Jindal
Ayush Jindal

Reputation: 103

How to set an environment variable for a shell from ant script?

I have a shell script user.sh that calls an ant script. The ant script prompts for some user input like

<input message="Enter the username" addproperty="my.user" />

I want to set an environment variable USER for the script user.sh from the ant script with the input value entered. I tried to do it like this:

<property environment = env />
<property name = env.USER value=my.user />

But it is not setting the environment variable in the shell script. How to set it in the parent shell script which was used to invoke the ant script?

Upvotes: 1

Views: 911

Answers (1)

Jayan
Jayan

Reputation: 18459

In your case, ant is sub process of shell. It is not possible to set parent process shell's environment variable from sub process. Other options are .

  1. Accept the user input from shell and set the variable.
  2. Write the obtained value from ant into a file, and source that file from parent shell. (some what like a call back).

Upvotes: 2

Related Questions