Bird
0
0

Given the script below, what will be the output?

medium📝 Command Output Q5 of 15
Bash Scripting - Quoting and Expansion
Given the script below, what will be the output?
greeting='world'
echo 'Hi, $greeting!'
AHi, world!
BHi, $greeting!
CHi, !
DHi, $greeting
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable assignment

    Variable greeting is assigned the string 'world'.
  2. Step 2: Effect of single quotes in echo

    Single quotes prevent variable expansion, so $greeting is printed literally.
  3. Final Answer:

    Hi, $greeting! -> Option B
  4. Quick Check:

    Variables inside single quotes are not expanded. [OK]
Quick Trick: Single quotes prevent variable expansion in echo. [OK]
Common Mistakes:
MISTAKES
  • Assuming $greeting expands inside single quotes.
  • Confusing single quotes with double quotes.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes