[英]Is there a way to escape a variable call in powershell?
我正在嘗試使用 powershell 為 Visual Studio 生成 build.include 腳本。 它們都使用${variable}
作為引用變量的一種方式。
我想知道是否有辦法在字符串中轉義它。
例如
$string = @'
This is a `${string} I want to escape and {0} one I do not want to
'@ -f $Var
我在網上看了,它說要逃避 $ 你必須使用反引號。 但似乎不適用於變量?
也許使用以下語法:
$Var = 'one'
$string = @"
This is a `$Var I want to escape and {0} I do not want to
"@ -f $Var
$string
生成以下 output:
This is a $Var I want to escape and one I do not want to
另一種選擇是嵌入變量:
@"
This is a `${Var} I want to escape and $Var I do not want to
"@
一些備注:
@""@
之間我想到了。 你必須放雙括號。
例子:
$string = @'
This is a ${{string}} I want to escape and {0} one I do not want to
'@ -f $Var
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.