Bird
0
0

What will be the output of this script?

medium📝 Command Output Q5 of 15
Bash Scripting - Quoting and Expansion
What will be the output of this script?
var="Hello World"
echo "$var"
echo $var
AHello World Hello World
BHello World Hello World
CHello World Hello World
DHello World Hello World
Step-by-Step Solution
Solution:
  1. Step 1: Analyze echo with double quotes

    First echo prints variable as one string 'Hello World'.
  2. Step 2: Analyze echo without quotes

    Second echo splits on space into 'Hello' 'World' but echo joins with space printing 'Hello World'.
  3. Final Answer:

    Hello World Hello World -> Option B
  4. Quick Check:

    Quoted preserves space; unquoted splits but echo rejoins = A [OK]
Quick Trick: Unquoted variables split on spaces; quote to keep intact [OK]
Common Mistakes:
MISTAKES
  • Thinking unquoted echo prints words on separate lines
  • Ignoring that echo joins arguments with space
  • Confusing newline with space

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes