Bird
0
0

Find the mistake in this array usage:

medium📝 Debug Q7 of 15
Bash Scripting - Arrays
Find the mistake in this array usage:
colors=(red green blue)
echo ${colors[1 2]}
AArray declaration is missing quotes
BArray elements must be separated by commas
Cecho cannot print array elements
DIncorrect index syntax; should access one index at a time
Step-by-Step Solution
Solution:
  1. Step 1: Review array element access syntax

    Array elements are accessed by a single index inside square brackets, e.g., colors[1].
  2. Step 2: Identify error in index usage

    Using multiple indexes like [1 2] is invalid syntax and causes an error.
  3. Final Answer:

    Incorrect index syntax; should access one index at a time -> Option D
  4. Quick Check:

    Access one index per array element [OK]
Quick Trick: Use one index inside brackets to access array elements [OK]
Common Mistakes:
MISTAKES
  • Using multiple indexes at once
  • Missing quotes in declaration
  • Misunderstanding echo capabilities

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes