如何在 Powershell 控制台中分配多行字符串

How to assign multiple lines string in Powershell Console

当我在 powershell 控制台中输入这个时

$test=@'
Test
Test'@

并且输入几次,它一直在打印

>>

所以我永远无法完成命令。

怎么办?

'@ 应该是行中的第一件事,或者它被认为只是字符串的一部分。

$test=@'
Test
Test
'@

这种方法也适用于 @"/"@

根据 maximum line length in The PowerShell Best Practices and Style Guide 的部分,我建议“splatting”字符串,如下所示:

$myStr = ("The family of Dashwood had long been settled in Sussex. Their estate was " +
              "large, and their residence was at Norland Park, in the centre of their " +
              "property, where, for many generations, they had lived in so respectable " +
              "a manner as to engage the general good opinion of their surrounding " +
              "acquaintance.")
$test=@'
Test
Test
'@

需要注意的重要一点是分隔符包括(不可见的)回车returns。起始标签末尾必须有一个,结束标签之前必须有一个