Bird
0
0

Find the error in this bash code:

medium📝 Debug Q7 of 15
Bash Scripting - Variables
Find the error in this bash code:
declare -i val=8
val=val*2
echo $val
AMissing quotes around val*2
Bdeclare -i cannot be used with val
Cval=val*2 is treated as string, not arithmetic
DSyntax error in echo statement
Step-by-Step Solution
Solution:
  1. Step 1: Analyze assignment

    Expression val=val*2 assigns string "val*2" to val, not arithmetic.
  2. Step 2: Correct arithmetic syntax

    Use val=$((val * 2)) to multiply correctly.
  3. Final Answer:

    val=val*2 is treated as string, not arithmetic -> Option C
  4. Quick Check:

    Arithmetic requires $(( )) in bash [OK]
Quick Trick: Use $(( )) for math, else it's string assignment [OK]
Common Mistakes:
MISTAKES
  • Assigning math without $(( ))
  • Misusing declare -i
  • Wrong echo syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes