开发者

How to escape trailing backslash in NVelocity

开发者 https://www.devze.com 2022-12-29 21:28 出处:网络
I am using NVelocity to process various PowerShell scripts before they 开发者_StackOverflow中文版are executed against a server.

I am using NVelocity to process various PowerShell scripts before they 开发者_StackOverflow中文版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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号