Bash Scripting - ArraysWhat is the correct syntax to access the second element of a Bash array named arr?Aecho ${arr(2)}Becho ${arr[1]}Cecho ${arr[2]}Decho ${arr.2}Check Answer
Step-by-Step SolutionSolution:Step 1: Remember Bash array indexingBash arrays start at index 0, so the second element is at index 1.Step 2: Use correct syntax for element accessThe syntax ${arr[1]} accesses the element at index 1 correctly.Final Answer:echo ${arr[1]} -> Option BQuick Check:Second element = ${arr[1]} [OK]Quick Trick: Array indexing starts at 0; second element is index 1 [OK]Common Mistakes:MISTAKESUsing parentheses instead of bracketsUsing 1-based indexing like ${arr[2]}Using dot notation which is invalid
Master "Arrays" in Bash Scripting9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Bash Scripting Quizzes Arrays - Array length - Quiz 12easy Arrays - Iterating over arrays - Quiz 11easy Error Handling - Why error handling prevents silent failures - Quiz 13medium Error Handling - Error logging patterns - Quiz 6medium Error Handling - set -o pipefail - Quiz 11easy File Operations in Scripts - Writing to files (echo, printf) - Quiz 7medium File Operations in Scripts - Appending to files (>>) - Quiz 12easy File Operations in Scripts - Why file I/O is core to scripting - Quiz 15hard Functions - Why functions organize reusable code - Quiz 11easy Text Processing in Scripts - Why scripts often process text - Quiz 9hard