PowerShell: Here-String

By Xah Lee. Date: . Last updated: .

What is Here-String

Here-string is a syntax for quoting long multi-lines text.

Here-String with APOSTROPHE delimiter (Literal)

Syntax

$x = @' text_body '@

Example

$x = @'
some
'@

$x -eq 'some'
# True

Here-String with QUOTATION MARK delimiter (Interpreted)

Syntax

$x = @" text_body "@

Similar to Here-String with APOSTROPHE delimiter, except that dollar sign $ sequence are considerd as expressions and GRAVE ACCENT ` is escape sequence.

Example

$x = 3

$text = @"
aa`nbb
$x cats
"@

$text
<#
aa
bb
3 cats
#>

PowerShell, string and regular expression