Bird
0
0

What is the problem with this PowerShell code snippet?

medium📝 Debug Q6 of 15
PowerShell - String Operations
What is the problem with this PowerShell code snippet?
$name = "Eve"
$text = 'Hello, $name!'
Write-Output $text
ADouble quotes cause a syntax error here.
BSingle quotes prevent variable $name from being expanded.
CVariable $name is undefined.
DWrite-Output cannot output variables.
Step-by-Step Solution
Solution:
  1. Step 1: Identify string delimiters

    Single quotes treat the string literally, no variable expansion.
  2. Step 2: Analyze output

    The output will be the literal string 'Hello, $name!' instead of 'Hello, Eve!'.
  3. Final Answer:

    Single quotes prevent variable $name from being expanded. -> Option B
  4. Quick Check:

    Use double quotes for variable expansion [OK]
Quick Trick: Single quotes do not expand variables [OK]
Common Mistakes:
  • Assuming single quotes expand variables
  • Thinking double quotes cause errors here
  • Believing Write-Output cannot print variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes