about_Escape_Characters
適用於: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0, Windows PowerShell 5.0
主題
about_Escape_Characters
簡短描述
介紹 Windows PowerShell® 中的逸出字元,並說明其效用。
詳細描述
逸出字元的用途是將特殊的解譯方式指派給它後面的字元。
在 Windows PowerShell,逸出字元是倒單引號 (`),也稱為抑音符號 (ASCII 96)。逸出字元可以用來指出常值、指出行接續符號,以及指出特殊字元。
在對另一個程式的呼叫中,您可以使用停止剖析符號 (--%) 防止 Windows PowerShell 錯誤解譯程式引數,不使用逸出字元。停止剖析符號於 Windows PowerShell 3.0 引入。
逸出變數
當逸出字元位於變數之前,它會防止變數的值被取代。
例如:
PS C:\>$a = 5
PS C:\>"The value is stored in $a."
The value is stored in 5.
PS C:\>$a = 5
PS C:\>"The value is stored in `$a."
The value is stored in $a.
逸出引號
當逸出字元位在雙引號之前,Windows PowerShell 會將雙引號解譯為字元,不解譯為字串分隔符號。
PS C:\> "Use quotation marks (") to indicate a string."
Unexpected token ')' in expression or statement.
At line:1 char:25
+ "Use quotation marks (") <<<< to indicate a string."
PS C:\> "Use quotation marks (`") to indicate a string."
Use quotation marks (") to indicate a string.
使用行接續符號
逸出字元會告訴 Windows PowerShell,命令在下一行繼續。
例如:
PS C:\> Get-Process `
>> PowerShell
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
340 8 34556 31864 149 0.98 2036 PowerShell
使用特殊字元
用在引號內時,逸出字元指出提供命令剖析器指示的特殊字元。
Windows PowerShell 會辨識下列特殊字元:
`0 Null
`a Alert
`b Backspace
`f Form feed
`n New line
`r Carriage return
`t Horizontal tab
`v Vertical tab
例如:
PS C:\> "12345678123456781`nCol1`tColumn2`tCol3"
12345678123456781
Col1 Column2 Col3
如需詳細資訊,請輸入:
Get-Help about_Special_Characters
停止剖析符號
在呼叫其他程式時,您可以使用停止剖析符號 (--%) 防止 Windows PowerShell 產生錯誤或錯誤解譯程式引數。停止剖析符號可以替代在程式呼叫中使用逸出字元。於 Windows PowerShell 3.0 引入。
例如,下列命令在 Icacls 命令中使用停止剖析符號:
icacls X:\VMS --% /grant Dom\HVAdmin:(CI)(OI)F
如需停止剖析符號的詳細資訊,請參閱 about_Parsing。
另請參閱
about_Quoting_Rules