Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Bash Scripting - Arrays
Identify the error in this code snippet:
myarray=(apple banana cherry)
echo ${myarray(1)}
AMissing quotes around elements
BArray not declared properly
CIncorrect echo command
DParentheses used instead of brackets
Step-by-Step Solution
Solution:
  1. Step 1: Check array element access syntax

    Bash arrays require brackets [] to access elements, not parentheses ().
  2. Step 2: Identify the error in code

    Using ${myarray(1)} causes syntax error; correct is ${myarray[1]}.
  3. Final Answer:

    Parentheses used instead of brackets -> Option D
  4. Quick Check:

    Use brackets [] for array access [OK]
Quick Trick: Always use brackets [] to access array elements [OK]
Common Mistakes:
MISTAKES
  • Using parentheses () instead of brackets []
  • Forgetting to declare array before access
  • Misplacing quotes inside array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes