Powershell转义字符`(反引号)未转义字符串

埃德蒙森

我在Powershell的字符串中添加新行时遇到麻烦:

Get-ChildItem "C:\Users\matt\Desktop\CShell Install" |foreach {'<Component Id="'+$_.name+'" Guid="' +[guid]::NewGuid() + '">`r`n<File Id="'+$_.name+'" Source="$(var.CShell.TargetPath)"></File></Component>'}

如您所见,我希望换行出现在

``r`n

相反,它们是按字面意思打印的。

有指针吗?

印度博览会

不要在您希望PowerShell遵守反引号(或需要PowerShell解释的任何其他字符)的地方使用单引号。

"FirstLine`r`nSecondLine" prints
FirstLine
SecondLine

'"FirstLine`r`nSecondLine"' prints
"FirstLine`r`nSecondLine"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章