Get the App
SLTechnology News&Howtos  ›  Servers  › 

Powershell escape character

Shulou Source: shulou.com Published: 2022-06-03 01:14:12 10月04日 Update

Let's talk about the escape characters of Powershell today.

What is an escape character? the escape character is a key in the upper left corner of the keyboard. After using the escape character, some characters with special meaning become ordinary characters, or some characters become other functional characters after using escape characters.

For example:

PS C:\ Windows\ system32 > $a=8PS C:\ Windows\ system32 > $b = "$an is 8" PS C:\ Windows\ system32 > $b8 is 8

Normally, the $symbol in double quotation marks is recognized as a variable, but if we add an escape character before the $symbol, then $will no longer be recognized as a variable, but as a normal character, as follows:

PS C:\ Windows\ system32 > $a=8PS C:\ Windows\ system32 > $b = "`$an is 8" PS C:\ Windows\ system32 > $Bologa is 8

In addition, escape characters are often used for code wrapping. If a line of code is too long to be displayed on the screen, we can wrap it by escaping characters without affecting the continuity of the code.

Get-WmiObject-Class win32_bios `| select serialnumberserialnumber-2VBCQF2

If we do not add escape characters after bios, then this code will report an error

PS C:\ Windows\ system32 > Get-WmiObject-Class win32_bios | Line where the select serialnumber is located: 2 characters: 1 + | select serialnumber+ ~ empty pipe elements are not allowed. + CategoryInfo: ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId: EmptyPipeElement

Another use of escape characters is to add escape characters to some character signatures, which are converted to certain functions rather than the original meaning of the characters, including the following

0 indicates that empty an emits a beep code

B rollback one character f page change, print the character, indicating to continue printing on the next page of the current character

N line feed r enter, the whole line before the character will be deleted

T horizontal Tabv vertical tab, the cursor advances to the next vertical tab stop and writes all subsequent outputs from there. This character only affects the printed document, not the screen output.

Tags: Character escape code influence normal function variable screen symbol output special line position element cursor content original can pass meaning upper left corner Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS vpn Linux Shulou Information Microsoft