Escaping Characters

Often a special character may be used—for example, in DOS commands—but PowerShell tries to interpret it differently. Let’s consider the dollar sign character ($). PowerShell normally tries to interpret it as a variable:

PS C:\> $var="$5 discount"PS C:\> $var discountPS C:\> $var="`$5 discount"PS C:\> $var$5 discountPS C:\>

The preceding example shows how the escape character, which is the backtick (`), is used to escape the dollar sign so that PowerShell doesn’t try to interpret the character literally as the beginning of a variable.

Note

You can execute the Get-Help about_escape_character command in PowerShell for more information and examples.

Get Microsoft® SQL Server 2012 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.