Expanding Variables in if statements

View: New views
2 Messages — Rating Filter:   Alert me  

Expanding Variables in if statements

by Michael Corr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi
I'm trying to check if a source string contains a substring, inside an <if> statement, but it doesn't seem to work when the source string is a variable

I have:
    <property name="dir.base" value="this/is/my/working/directory" />
    <if test="${string::contains('${dir.base}','working')}">
      <echo>This is my directory</echo>
    </if>

This never returns true. It doesn't seem to parse the ${dir.base} variable inside the <if> statement

If I change the test to:
    <if test="${string::contains('${dir.base}','base')}">
      <echo>This is my directory</echo>
    </if>

This does return true. So, it appears to treat the variable as a literal and not a variable.

Am I missing something? I tried removing the single quotes around ${dir.base} and got an error about the $ character. I also tried using double quotes, but got an error as well

Is there a better way to check if a string (or path) contains a specific directory?

thanks
Michael


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
NAnt-users mailing list
NAnt-users@...
https://lists.sourceforge.net/lists/listinfo/nant-users

Re: Expanding Variables in if statements

by Bob Archer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

You don't not embed expressions. Write your if as follows:

 

    <property name="dir.base" value="this/is/my/working/directory" />
    <if test="${string::contains(dir.base,'working')}">
      <echo>This is my directory</echo>
    </if>

 

 

BOb

 

 

From: Michael Corr [mailto:michael@...]
Sent: Sunday, August 30, 2009 10:52 PM
To: nant-users@...
Subject: [NAnt-users] Expanding Variables in if statements

 

hi
I'm trying to check if a source string contains a substring, inside an <if> statement, but it doesn't seem to work when the source string is a variable

I have:
    <property name="dir.base" value="this/is/my/working/directory" />
    <if test="${string::contains('${dir.base}','working')}">
      <echo>This is my directory</echo>
    </if>

This never returns true. It doesn't seem to parse the ${dir.base} variable inside the <if> statement

If I change the test to:
    <if test="${string::contains('${dir.base}','base')}">
      <echo>This is my directory</echo>
    </if>

This does return true. So, it appears to treat the variable as a literal and not a variable.

Am I missing something? I tried removing the single quotes around ${dir.base} and got an error about the $ character. I also tried using double quotes, but got an error as well

Is there a better way to check if a string (or path) contains a specific directory?

thanks
Michael


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
NAnt-users mailing list
NAnt-users@...
https://lists.sourceforge.net/lists/listinfo/nant-users