You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Pankaj Kumar <pa...@gmail.com> on 2005/08/09 16:41:31 UTC

How to test whether a particular environment variable is set or not

Hi Folks,

I want to set a property to the value of an environment variable if
that variable is set, otherwise to a different string.

I am able to do this with the following:

    <property environment="env" />
    
    <property name="test.home.0" value="${env.TEST_HOME}"/>
    <condition property="test.home" value="TO_BE_REPLACED">
      <equals arg1="${test.home.0}" arg2="\${env.TEST_HOME}"/>
    </condition>
    <property name="test.home" value="${env.TEST_HOME}"/>
    
    <target name="test">
      <echo>TEST_HOME: ${test.home}</echo>
    </target>

Is there a better (read: less verbose) way?

Thanks,
Pankaj Kumar.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: How to test whether a particular environment variable is set or not

Posted by Pankaj Kumar <pa...@gmail.com>.
On 8/9/05, Antoine Levy-Lambert <an...@gmx.de> wrote:

> this is another alternative for the same :
> <property environment="env"/>
> <property name="env.TEST_HOME" value="TO_BE_REPLACED"/>
> 
Hi Antoine,

This works. It is also more compact and elegant (compared to my
version). Thanks.

/Pankaj.
> ----- Original Message -----
> From: "Pankaj Kumar" <pa...@gmail.com>
> To: <us...@ant.apache.org>
> Sent: Tuesday, August 09, 2005 4:41 PM
> Subject: How to test whether a particular environment variable is set or not
> 
> 
> Hi Folks,
> 
> I want to set a property to the value of an environment variable if
> that variable is set, otherwise to a different string.
> 
> I am able to do this with the following:
> 
>    <property environment="env" />
> 
>    <property name="test.home.0" value="${env.TEST_HOME}"/>
>    <condition property="test.home" value="TO_BE_REPLACED">
>      <equals arg1="${test.home.0}" arg2="\${env.TEST_HOME}"/>
>    </condition>
>    <property name="test.home" value="${env.TEST_HOME}"/>
> 
>    <target name="test">
>      <echo>TEST_HOME: ${test.home}</echo>
>    </target>
> 
> Is there a better (read: less verbose) way?
> 
> Thanks,
> Pankaj Kumar.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: How to test whether a particular environment variable is set or not

Posted by Ninju Bohra <ni...@yahoo.com>.
Using the <if> task (from the ant-contrib project) you
can do it like this:

   <if>
      <isset property="env.TEST_HOME"/>
      <then>
         <property name="test.home"
value="${env.TEST_HOME}/>
      </then>
      <else>
         <property name="test.home"
value=""TO_BE_REPLACED"/>
      </else>
   </if>

Though I am not sure if it is less verbose, it is more
readable at least


--- Antoine Levy-Lambert <an...@gmx.de> wrote:

> hello Kumar,
> 
> this is another alternative for the same :
> <property environment="env"/>
> <property name="env.TEST_HOME"
> value="TO_BE_REPLACED"/>
> 
> might work.
> 
> Cheers,
> 
> Antoine
> 
> 
> 
> ----- Original Message ----- 
> From: "Pankaj Kumar" <pa...@gmail.com>
> To: <us...@ant.apache.org>
> Sent: Tuesday, August 09, 2005 4:41 PM
> Subject: How to test whether a particular
> environment variable is set or not
> 
> 
> Hi Folks,
> 
> I want to set a property to the value of an
> environment variable if
> that variable is set, otherwise to a different
> string.
> 
> I am able to do this with the following:
> 
>     <property environment="env" />
> 
>     <property name="test.home.0"
> value="${env.TEST_HOME}"/>
>     <condition property="test.home"
> value="TO_BE_REPLACED">
>       <equals arg1="${test.home.0}"
> arg2="\${env.TEST_HOME}"/>
>     </condition>
>     <property name="test.home"
> value="${env.TEST_HOME}"/>
> 
>     <target name="test">
>       <echo>TEST_HOME: ${test.home}</echo>
>     </target>
> 
> Is there a better (read: less verbose) way?
> 
> Thanks,
> Pankaj Kumar.
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 






		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: How to test whether a particular environment variable is set or not

Posted by Antoine Levy-Lambert <an...@gmx.de>.
hello Kumar,

this is another alternative for the same :
<property environment="env"/>
<property name="env.TEST_HOME" value="TO_BE_REPLACED"/>

might work.

Cheers,

Antoine



----- Original Message ----- 
From: "Pankaj Kumar" <pa...@gmail.com>
To: <us...@ant.apache.org>
Sent: Tuesday, August 09, 2005 4:41 PM
Subject: How to test whether a particular environment variable is set or not


Hi Folks,

I want to set a property to the value of an environment variable if
that variable is set, otherwise to a different string.

I am able to do this with the following:

    <property environment="env" />

    <property name="test.home.0" value="${env.TEST_HOME}"/>
    <condition property="test.home" value="TO_BE_REPLACED">
      <equals arg1="${test.home.0}" arg2="\${env.TEST_HOME}"/>
    </condition>
    <property name="test.home" value="${env.TEST_HOME}"/>

    <target name="test">
      <echo>TEST_HOME: ${test.home}</echo>
    </target>

Is there a better (read: less verbose) way?

Thanks,
Pankaj Kumar.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org