Bird
0
0

What will this script print?

medium📝 Command Output Q5 of 15
Bash Scripting - Functions
What will this script print?
add() {
  echo $(( $1 + $2 ))
}
add 5 3
A53
B$1 + $2
C8
DError: syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand arithmetic expansion

    The expression $(( $1 + $2 )) calculates the sum of the first and second arguments passed to the function.
  2. Step 2: Calculate the sum of 5 and 3

    5 + 3 equals 8, so the echo prints 8.
  3. Final Answer:

    8 -> Option C
  4. Quick Check:

    Arithmetic expansion sums arguments correctly = 8 [OK]
Quick Trick: Use $(( )) for arithmetic in bash functions [OK]
Common Mistakes:
MISTAKES
  • Concatenating strings instead of adding
  • Missing spaces inside $(( ))
  • Using quotes around arithmetic expression

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes