我做了一些谷歌搜索,似乎无法找到一个有效的方法来显示整个文本块到控制台.Write-Host如果我需要显示一段代码,我宁愿不在每一行使用该命令.我正在尝试制作一个有点美观的互动脚本.有人可以给我一个例子吗?
PowerShell支持多行字符串,或者作为here-strings:
Write-Host @"
Some text you
want to span
multiple lines.
"@
Run Code Online (Sandbox Code Playgroud)
或常规字符串:
Write-Host "Some text you
want to span
multiple lines."
Run Code Online (Sandbox Code Playgroud)
除了 Ansgar 的例子,它也Write-Host接受一个数组。
'one','two','three' | Write-Host
Run Code Online (Sandbox Code Playgroud)
So whether your multi-line string is a single string, or an array of lines, it will still work as expected with a single Write-Host call:
Get-Content mycode.txt | Write-Host
Get-Content mycode.txt -Raw | Write-Host
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11215 次 |
| 最近记录: |