Bird
0
0

What will be the output of this script run in sh but not in Bash?

medium📝 Command Output Q5 of 15
Bash Scripting - Basics
What will be the output of this script run in sh but not in Bash?
echo $(( 1 + 2 ))
A3
B1 + 2
CSyntax error
DEmpty output
Step-by-Step Solution
Solution:
  1. Step 1: Understand arithmetic expansion support

    Bash supports $(( )) arithmetic expansion; many modern sh versions also support it.
  2. Step 2: Predict behavior in sh

    Most modern sh shells support arithmetic expansion, so it outputs 3.
  3. Final Answer:

    3 -> Option A
  4. Quick Check:

    Arithmetic expansion supported in sh = Outputs 3 [OK]
Quick Trick: Most sh versions support $(( )) arithmetic expansion [OK]
Common Mistakes:
MISTAKES
  • Assuming sh does not support $(( ))
  • Expecting syntax error in sh
  • Thinking it prints expression literally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes