on-internet
← Community

PowerShell Nested Here-String

Stack Overflow ·

Placing the following within a script will fail: $MyString = @' hello @' '@ bye '@ write-host $MyString The error returned is as follows: At C:\scripts\test.ps1:6 char:1 + '@ + ~~ The string is missing the terminator: '. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString Prefixing the nested @' and '@ with a backtick (grave accent) does serve as an escape character, however it is also treated as literal, and therefore appears in the output of $MyString. Is there a correct way to escape a single quoted here-string within a single quote

Comments

Sign in or sign up to comment and upvote.

No comments yet.