Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q6 of 15
Bash Scripting - Variables
Identify the error in this script snippet:
declare -i num=5
num=num+3
echo $num
AWrong variable name
BMissing $(( )) for arithmetic evaluation
Cdeclare -i cannot be used with num
DSyntax error in declare statement
Step-by-Step Solution
Solution:
  1. Step 1: Check arithmetic assignment

    Assigning num=num+3 treats right side as string, not arithmetic.
  2. Step 2: Correct syntax for arithmetic

    Use num=$((num + 3)) to evaluate arithmetic expression.
  3. Final Answer:

    Missing $(( )) for arithmetic evaluation -> Option B
  4. Quick Check:

    Arithmetic needs $(( )) in bash [OK]
Quick Trick: Always use $(( )) for arithmetic assignments [OK]
Common Mistakes:
MISTAKES
  • Assigning arithmetic without $(( ))
  • Using wrong variable names
  • Misusing declare -i

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes