Bird
0
0

What will be the output of this script?

medium📝 Command Output Q5 of 15
Bash Scripting - Functions
What will be the output of this script?
add() {
  echo $(( $1 + $2 ))
}
add 3 7
AError: invalid syntax
B37
C10
D3 7
Step-by-Step Solution
Solution:
  1. Step 1: Understand function and arithmetic evaluation

    The function add sums its two arguments using arithmetic expansion $(( )).
  2. Step 2: Calculate the sum of 3 and 7

    3 + 7 equals 10, so the function outputs 10.
  3. Final Answer:

    10 -> Option C
  4. Quick Check:

    Arithmetic expansion sums arguments correctly [OK]
Quick Trick: Use $(( )) for arithmetic inside functions [OK]
Common Mistakes:
MISTAKES
  • Concatenating arguments instead of adding
  • Missing arithmetic expansion
  • Syntax errors in function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes