Talk today about the escape character for PowerShell
What is an escape character, the escape character in the upper-left corner of the keyboard and ~ is a key that uses the escape character to turn some special characters into normal characters, or to use escape characters for some characters to become additional functional characters
For example:
PS C:\Windows\system32> $a=8PS C:\Windows\system32> $b="$a is 8"PS C:\Windows\system32> $b8 is 8
Normally, the $ symbol in double quotes is recognized as a variable, but if we add an escape character before the $ symbol, then $ is no longer recognized as a variable, but as a normal character, as follows:
PS C:\Windows\system32> $a=8PS C:\Windows\system32> $b="`$a is 8"PS C:\Windows\system32> $b$a is 8
In addition, the escape character is often used for code wrapping, and if a line of code is too long to exceed the display range of the screen, then we can break the line by escaping the character without affecting the continuity of the code.
Get-WmiObject -Class win32_bios `| select serialnumberserialnumber------------2VBCQF2
If we do not include an escape character after the BIOS, the code will error
PS C:\Windows\system32> Get-WmiObject -Class win32_bios | select serialnumber所在位置 行:2 字符: 1+ | select serialnumber+ ~不允许使用空管道元素。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : EmptyPipeElement
Another use of escape characters is to add an escape character to certain character signatures, which are converted to certain functions rather than the original character meaning, in the following ways
0 表示空<br/>
A beep noise
b 回退一个字符<br/>
F page breaks, printing characters, indicating that the next page of the current character continues to print
n 换行<br/>
R Enter to delete the entire line before the character
t 水平Tab<br/>
V Vertical tab, the cursor advances to the next vertical tab stop and starts writing to all subsequent outputs. This character affects only the printed document and does not affect the screen output
Powershell Escape character