双引号中的Powershell变量
我有一个PS脚本,它应该生成一个包含add content$datei的html文件 很好,但问题是, 我有这样的想法:双引号中的Powershell变量,powershell,escaping,Powershell,Escaping,我有一个PS脚本,它应该生成一个包含add content$datei的html文件 很好,但问题是, 我有这样的想法: "some html... <textarea id="Text$counter" style="width: 100%; height: 100%;"></textarea> some html... <span>$NameEdit</span> some html... document.getElementById('Te
"some html...
<textarea id="Text$counter" style="width: 100%; height: 100%;"></textarea>
some html...
<span>$NameEdit</span>
some html...
document.getElementById('Text$counter').select();
some html...
" | add-content $datei
“一些html。。。
一些html。。。
$namedit
一些html。。。
document.getElementById('Text$counter').select();
一些html。。。
“|添加内容$datei
因此,我在html部分中有多个双qoutes和单qoutes以及多个变量,但我无法找到如何正确地转义脚本按预期运行的所有内容,并在html代码中填充变量
im使用PS 7.0您可能需要的解决方案是这里的字符串 但是您也可以使用转义字符`
@"
some html...
<textarea id="Text$counter" style="width: 100%; height: 100%;"></textarea>
some html...
<span>$NameEdit</span>
some html...
document.getElementById('Text$counter').select();
some html...
"@ | add-content $datei
下面是几个正确工作的例子
#This WILL work
@"
Hey There "Buddy"
"@
#This WILL work
@"
Hey There "Buddy"
"@
#This WILL work
$Test = @"
Hey There "Buddy"
"@
它确实使美化代码变得更加困难
范例
现在让我们看一下转义字符`
它被称为反向勾选
"Hey There `"Buddy`""
等于嘿,这里是“Buddy”你应该看看这里的字符串和-f(format)操作符。我读过这篇文章和其他一些网站,但从来没有一个例子说明我遇到的问题:/
Function Test(){
$Text1 = "Hello There"
$Text2 = @"
"Buddy"
"@
return "$Text1 $Text2"
}
"Hey There `"Buddy`""