简体   繁体   English

如何在交互式PowerShell窗口中编写多行“for”循环?

[英]How to write a multiline “for” loop in the interactive PowerShell window?

I Googled a lot and someone said ` (backtick) can be used for line continuation but it does not work for me. 我google了很多,有人说`(反引号)可以用于续行,但它对我不起作用。 I tried following but both would not work. 我试过跟随,但两个都行不通。

PS C:\> foreach ($i in 1,2) { echo $i; }
1
2
PS C:\> foreach ($i in 1,2) {
>> echo $i;
>> }
>>        <== It's still waiting for input. Killed with Ctrl-C.
PS C:\> foreach ($i in 1,2) { `
>> echo $i; `
>> }
>>        <== It's still waiting for input. Killed with Ctrl-C.
PS C:\>

You don't need to use backticks (or i didnt have to) 你不需要使用反引号(或者我不需要)

but you do need to press enter a second time. 但你确实需要再次按回车键。

PS C:\> foreach ($i in 1,2) { echo $i; }
1
2
PS C:\> foreach ($i in 1,2) {
>> echo $i;
>> }
>>        <== Press enter again here.
1
2
PS C:\>

I presume this then lets the interpreter know that command has finished and allows it to execute. 我假设这使得解释器知道命令已经完成并允许它执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在powershell中调用第二个窗口并写入它 - How to call a second window in powershell and write to it 如何在 Azure 管道 PowerShell 任务中编写内联多行 powershell 脚本? - How do I write an inline multiline powershell script in an Azure Pipelines PowerShell task? 如何在 PowerShell 中使用循环编写 XML 文件? - How to write XML file with loop in PowerShell? 在交互式提示符下编写命令(powershell 或 bat) - write command in interactive prompt (powershell or bat) Powershell多行正则表达式:字幕,如何? - Powershell multiline regex: subtitles , How? 如何在 PowerShell 中编写多行脚本? 我也尝试使用 Backtick 但没有用 - How to write multiline Scripts in PowerShell ? I tried using Backtick also but didnt work 在交互式Powershell窗口(如Powershell ISE)中使用“ Visual Studio代码” - Using “Visual Studio code” with interactive Powershell window like Powershell ISE Powershell 如何通过管道传输交互式命令 - Powershell how to pipe an interactive command 如何在 foreach 循环中使用 Powershell 写入 CSV 中的一个条目 - How to write to one entry in a CSV with Powershell in foreach loop 如何写入托管 Powershell 中每个循环的唯一结果列表? - How to write to host a list of unique results from a for each loop in Powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM