Search code examples
ant

Is there a way to esacpe "@" in ant build


I'm trying to echo a list of file names to a file with 2 @ appended as prefix
E.g.
@@some_filename
@@some_filename2

Below is what I'm doing currently which works fine and outputs as expected except its done in a really dumb way.

<fileset id="filesref" dir="some_path" includes="**/*.txt"/>
<property name="files" refid="filesref"/>
<for list="${files}" delimiter=";" param="file" >
    <sequential>
        <echo file="somefile" message="@@@@@{file}${line.separator}" append="true"/>
    </sequential>
</for>

Is there a way to escape @ sign so my message could prob look something like below (let's say if \ escapes)

<echo file="somefile" message="\@\@@{file}${line.separator}"/>

Thanks in advance.


Solution

  • You only need to escape the @s in the antcontrib tasks where it has a special meaning (variable sigil). You can do this to make it a bit easier on the eye:

    <property name="prefix" value="@@" />
    
    <for list="${files}" delimiter=";" param="file" >
      <sequential>
        <echo file="somefile" append="yes" message="${prefix}@{file}${line.separator}"/>
      </sequential>
    </for>