ScriptingLesson 52Free preview
Bash Arrays
This lesson is part of Bash · All levels
Summary
Bash arrays store many values in one variable, created with parentheses containing a list of values separated by spaces. Elements are accessed via an index starting from 0, whereas @ takes the entire element. Bash also provides a way to calculate array lengths and key-based associative arrays.
Key points
- Arr=(a b c) makes an array, the index starts from 0
- ${arr[0]} takes the first element
- ${arr[@]} takes the whole element
- ${#arr[@]} count the number of elements
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.