Search code examples
velocitynvelocityvtl

How to escape trailing backslash in NVelocity


I am using NVelocity to process various PowerShell scripts before they are executed against a server.

My question is how to escape a backslash trailing a variable:

e.g.

ls \\$computername\c$

$computername should be replaced with a valid computer name at runtime, but the trailing backslash (\c$) means that it does not.

Thanks Ben


Solution

  • Mauricio's suggestion did not work for me. I think this because I was referencing the c$ admin share and Velocity uses the '$' sign to declare variables/objects.

    Instead I created variables to contain such references so my solution was:

    #set ($C = '\c$')
    ls \\\\$computername$C
    

    As per http://velocity.apache.org/engine/devel/user-guide.html#escapingvalidvtlreferences