PowerShell: Quote String

By Xah Lee. Date: . Last updated: .

Double Quoted String

Double quoted string is expandable quote, variable inside are expanded. Example:

"there are $n cats"

Expression is also expanded. Example:

"there are $(2+1) cats"

to escape a dollar sign inside double quoted string, precede it with GRAVE ACCENT `. Example:

"there are `$n cats"

to include a double quote inside a double quoted string, precede it with GRAVE ACCENT `. Example:

"He said: ""yes"""

"He said: `"yes`""

Single Quoted String

Single quote is literal. To include a single quote inside single quoted string, use two single quotes Example:

'don''t'

here-string

“here-string” is a syntax to quote literal long text.

There are two syntaxes, double quote or single quote:

example:

@"
long string here
maybe multiple lines
some variable $n cats
can contain many quotes "" '' tick ` or slashes / \
"@
@'
long string here.
everything is literal
variable $n are not intepreted
can contain many quotes "" '' tick ` or slashes / \
'@

In either syntax, the closing quotation mark must be the first character in the line.

If you have a question, put $5 at patreon and message me.

PowerShell

xah powershell logo

More Advanced