Bird
0
0

Find the error in this bash array usage:

medium📝 Debug Q14 of 15
Bash Scripting - Arrays
Find the error in this bash array usage:
myarray=(one two three)
echo $myarray[2]
AMissing quotes around array items
BArray declaration syntax is wrong
CIncorrect way to access array element
DNo error, script runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check array declaration

    Declaration with parentheses is correct: myarray=(one two three).
  2. Step 2: Check array element access

    Access must use braces: ${myarray[2]}, not $myarray[2].
  3. Final Answer:

    Incorrect way to access array element -> Option C
  4. Quick Check:

    Use ${array[index]} to access elements [OK]
Quick Trick: Use braces ${} to access array elements [OK]
Common Mistakes:
MISTAKES
  • Using $array[index] without braces
  • Adding commas in declaration
  • Forgetting parentheses in declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes