0

I am looking for away to load a variable with a combination of text and content of other vars, but in separate lines. i.e.

$a=text1
$b=text2
$c = "text"
(line2) $a
(line3) $b

So in $c i would like to store $a and $b plus some text in different lines and show it up with write-host

'write-host $c'

i tried

$c=@'
this is line1
line2: contains $a
line3: contains $b
@'

but instead of the value of the vars I get $a, $b etc```
2
  • Does this answer your question? string variable not substituted in multi-line string Commented Apr 3, 2023 at 8:22
  • Quoting in PowerShell is like ksh/bash/etc. Strings enclosed in QUOTATION MARK characters get interpolated. Strings enclosed in APOSTROPHE characters are as-is, without interpolation. Commented Apr 3, 2023 at 13:41

1 Answer 1

3

The correct and working script is the following:

$a = "text1"
$b = "text2"
$c = @"
this is line1
line2: contains $a
line3: contains $b
"@

Write-Host $c

You must use double quotes and the @ character is in a wrong place in your script.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.