Bird
0
0

What will be the output of this script?

medium📝 Command Output Q5 of 15
Bash Scripting - Variables
What will be the output of this script?
var="5"
echo "$var2"
echo "${var}2"
A 52
B5 52
C 5 2
D52 52
Step-by-Step Solution
Solution:
  1. Step 1: Analyze first echo "$var2"

    Variable var2 is undefined, so it prints empty line.
  2. Step 2: Analyze second echo "${var}2"

    Braces separate var from 2, so it prints 5 followed by 2, resulting in 52.
  3. Final Answer:

    (empty line) 52 -> Option A
  4. Quick Check:

    Undefined var empty, braces separate = A [OK]
Quick Trick: Use braces to avoid variable name confusion [OK]
Common Mistakes:
MISTAKES
  • Expecting $var2 to print 5
  • Not using braces to separate variable and text
  • Assuming undefined variables print error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes