Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

powershell

What is `n in Powershell?

Khizar Hayat Saani

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

Powershell is an open-source, cross-platform shell and scripting language. It is built on top of Microsoft’s .NET framework.

A shell in Computer Science is a user interface that allows interaction with the operating system.

Like any other language, Powershell has its commands and syntax. We will be discussing `n, as used in Powershell.

The `n and \n charaters

Usage

`n is used in Powershell to append a new line to the standard output.

The use of `n in Powershell is similar to \n in C++ or Java.

The backtick character (`) represents an escape character in Powershell.

An escape character lets us print otherwise unprintable characters to the standard output.

The purpose of escape characters is to represent whitespace characters like: \t (tab), \n (newline), and \r (carriage return). An escape character can be prefixed to a special character to convert into an ordinary character.

Note: Powershell can only interpret escape characters when enclosed within double quotes (" ").

Code

Write-Host "``n"
# prints the newline char (`n) as an ordinary character

Write-Host "Hello`nWorld"
#prints Hello World separated by a new line.

Output

`n
Hello
World

Try it yourself

Try the above code in the terminal below to see the command in action and produce the result.

Terminal 1
Terminal

RELATED TAGS

powershell

CONTRIBUTOR

Khizar Hayat Saani
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring