Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break lines in PowerShell?

I am [completely new to PowerShell and] concatenating a string in a loop, if a special condition occurs I should insert a line break...how can I do this?

Basically looking for the equivalent of \n.

$str = "" foreach($line in $file){   if($line -Match $review){ #Special condition     $str += ANSWER #looking for ANSWER   }   #code..... } 

So far I have tried

"\n" '\n' "\N" '\N' "\r" '\r' "\R" '\R' '`n' '`r' '-n' '-r'  
like image 755
user454322 Avatar asked Aug 09 '12 04:08

user454322


People also ask

How do you create a line break in PowerShell?

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

How do you skip a line in PowerShell?

In PowerShell, using Get-Content to skip first line of file, use Skip parameter with value to skip line.

How do I run multiple lines in PowerShell?

In PowerShell and PowerShell ISE, it is also possible to use Shift + Enter at the end of each line for multiline editing (instead of standard backtick ` ).

How do you break a line in a script?

To create a line break in JavaScript, use “<br>”.


2 Answers

Try "`n" with double quotes. (not single quotes '`n' )

For a complete list of escaping characters see:

Help about_Escape_character

The code should be

$str += "`n" 
like image 184
Neverever Avatar answered Sep 21 '22 18:09

Neverever


I think I found it. All you have to do is type in "`n" (WITH THE QUOTATION MARKS!)

Thanks!

like image 42
New to PowerShell Avatar answered Sep 20 '22 18:09

New to PowerShell