Bird
0
0

What will this script output?

medium📝 Command Output Q5 of 15
Bash Scripting - Variables
What will this script output?
var=5
var=$((var + 3))
echo $var
AError
B5 + 3
Cvar + 3
D8
Step-by-Step Solution
Solution:
  1. Step 1: Understand arithmetic expansion

    $((var + 3)) calculates the sum of var and 3, which is 5 + 3 = 8.
  2. Step 2: Assign and print the new value

    var is updated to 8, so echo prints 8.
  3. Final Answer:

    8 -> Option D
  4. Quick Check:

    Arithmetic expansion updates variable = D [OK]
Quick Trick: Use $(( )) for math in variables [OK]
Common Mistakes:
MISTAKES
  • Printing expression as string
  • Not using $(( )) for math
  • Expecting error from arithmetic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes