Bird
0
0

What will be the output of the following bash script?

medium📝 Command Output Q13 of 15
Bash Scripting - Quoting and Expansion
What will be the output of the following bash script?
#!/bin/bash
x=5
y=3
result=$((x * y + 2))
echo $result
A17
B21
C15 + 2
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Substitute variable values in the expression

    x=5 and y=3, so expression is 5 * 3 + 2.
  2. Step 2: Calculate the arithmetic expression

    5 * 3 = 15, then 15 + 2 = 17.
  3. Final Answer:

    17 -> Option A
  4. Quick Check:

    5 * 3 + 2 = 17 [OK]
Quick Trick: Calculate multiplication before addition inside $(( )) [OK]
Common Mistakes:
MISTAKES
  • Treating expression as string concatenation
  • Ignoring operator precedence
  • Expecting syntax error due to variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes