When including a literal quote character inside a quoted string in Powershell, how do I escape the quote character to indicate it is a literal instead of a string delimeter?
When including a literal quote character inside a quoted string in Powershell, how do I escape the quote character to indicate it is a literal instead of a string delimeter?
From
help about_quoting_rules
The use of the backtick character to escape other quotation marks in single quoted strings is not supported in recent versions of PowerShell. In earlier versions of PowerShell the backtick escape character could be used to escape a double quotation mark character within a single quoted string as detailed in the
help about_quoting
document that is available in those versions of PowerShell.The escape character in Powershell is the "`" (backward apostrophe/grave).
This can be used to escape quotes and also special characters (e.g., tab is `t).
To compliment what has already been provided here, you should also know that you can escape a quote (single or double) with the quote itself. That means you can do this:
"Here's an example of a ""double-quoted string""."
and this:
'This time it''s ''single-quoted''.'
The advantage this syntax provides is simple: it's easier to type the same quote twice than it is to escape a quote with a backtick.
single 'text' so it is treated as literal text, then escape any special characters using "\"
e.g. This string: "As they say, "live and learn."" Becomes this string 'As they say, \"live and learn.\"'