How to assign multiple lines string in Powershell Console

半世苍凉 提交于 2020-08-24 05:39:06

问题


When I do enter this in powershell Console

$test=@'
Test
Test'@

And do enter several times, it keeps printing

>>

So I can never finish command.

What to do ?


回答1:


'@ should be first thing in the line or it is considered to be just a part of the string.

$test=@'
Test
Test
'@

This approach also works with @"/"@




回答2:


As per the section on maximum line length in The PowerShell Best Practices and Style Guide, I would suggest “splatting” the string, like this:

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



回答3:


$test=@'
Test
Test'@

The important thing to note is that the delimiters include (invisible) carriage returns. There must be one at the end of the starting tag, and one before the closing tag.



来源:https://stackoverflow.com/questions/31793449/how-to-assign-multiple-lines-string-in-powershell-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!