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

时间:2015-08-03 17:39:50

标签: string powershell multiline

当我在powershell控制台中输入此内容时

$test=@'
Test
Test'@

并且多次输入,它会一直打印

>>

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

怎么办?

3 个答案:

答案 0 :(得分:13)

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

'@

此方法也适用于$test=@' Test Test '@ / @"

答案 1 :(得分:1)

根据maximum line lengthThe PowerShell Best Practices and Style Guide的部分,我建议将字符串“撒上”,就像这样:

$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.")

答案 2 :(得分:1)

$test=@'
Test
Test'@

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