Bird
0
0

Find the mistake in this bash snippet:

medium📝 Debug Q6 of 15
Bash Scripting - Arrays
Find the mistake in this bash snippet:
list=(red green blue)
count=${#list}
echo $count
AMissing quotes around array elements
BUsing ${#list} instead of ${#list[@]} to get array length
CIncorrect array declaration syntax
DUsing echo instead of printf
Step-by-Step Solution
Solution:
  1. Step 1: Understand ${#list}

    This returns length of first element, not number of elements.
  2. Step 2: Correct syntax

    Use ${#list[@]} to get the count of elements.
  3. Final Answer:

    Using ${#list} instead of ${#list[@]} to get array length -> Option B
  4. Quick Check:

    Use [@] to get array size [OK]
Quick Trick: Use ${#array[@]} for length, not ${#array} [OK]
Common Mistakes:
MISTAKES
  • Confusing length of first element with array size
  • Forgetting [@] in length expression
  • Assuming ${#array} gives number of elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes