Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to end a multi-line command in PowerShell

Tags:

This should be easy, but can't figure it out. How do I end a multi-line command in PowerShell? For example if I enter Get-ChildItem | and press enter then I get a >> prompt which I assume is to continue the command. But if I then enter foreach{Write-Host $_.name} and press enter I still get the >> prompt.

How do I say, I'm done, run this now? I thought it would happen when I wrote a complete command (not ending with a pipe or an unclosed bracket), but doesn't seem to. Also tried ending with a semi-colon, but that didn't help much.

like image 718
Svish Avatar asked Nov 05 '12 09:11

Svish


People also ask

How do you end a PowerShell command?

Let's practice! Open a PowerShell console session, type exit , and press the Enter key. The PowerShell console will immediately close. This keyword can also exit a script rather than the console session.

How do you break a line in a PowerShell script?

Using PowerShell newline in Command To add newline in the PowerShell script command, use the` (backtick) character at the end of each line to break the command into multiple lines.

What is Ctrl break in PowerShell?

In the PowerShell console you use the Ctrl+Break key combination to break into the debugger.

What does %% mean in PowerShell?

% is an alias for the ForEach-Object cmdlet. An alias is just another name by which you can reference a cmdlet or function.


2 Answers

And right after I asked, I figured it out... Hitting Enter twice made it happen :)

like image 160
Svish Avatar answered Sep 19 '22 16:09

Svish


If you continue to get >> prompts after pressing enter twice, check your script for unterminated strings, i.e., unpaired quotes.

like image 23
Michael Avatar answered Sep 17 '22 16:09

Michael