Bird
0
0

What will be the output of this script?

medium📝 Command Output Q5 of 15
Bash Scripting - User Input
What will be the output of this script?
echo "Enter two numbers:"
read a b
echo "$a plus $b equals $((a + b))"
APrints sum of two numbers entered
BPrints the literal string with variables
CThrows syntax error due to arithmetic
DPrints only the first number
Step-by-Step Solution
Solution:
  1. Step 1: Read two numbers into variables

    read a b stores first and second inputs into a and b.
  2. Step 2: Use arithmetic expansion

    $((a + b)) calculates sum of a and b.
  3. Final Answer:

    Prints sum of two numbers entered -> Option A
  4. Quick Check:

    Arithmetic expansion works with read variables [OK]
Quick Trick: Use $(( )) to calculate with read variables [OK]
Common Mistakes:
MISTAKES
  • Expecting literal variable names printed
  • Thinking arithmetic causes error
  • Assuming only one variable is read

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes