Concept Flow - Indexed array declaration
Start script
Declare indexed array
Assign values to array elements
Access or print array elements
End script
This flow shows how a bash script declares an indexed array, assigns values, and accesses them.
fruits=("apple" "banana" "cherry") echo ${fruits[0]} echo ${fruits[1]} echo ${fruits[2]}
| Step | Action | Array State | Output |
|---|---|---|---|
| 1 | Declare array fruits with elements apple, banana, cherry | ["apple", "banana", "cherry"] | |
| 2 | Print fruits[0] | ["apple", "banana", "cherry"] | apple |
| 3 | Print fruits[1] | ["apple", "banana", "cherry"] | banana |
| 4 | Print fruits[2] | ["apple", "banana", "cherry"] | cherry |
| 5 | End of script | ["apple", "banana", "cherry"] |
| Variable | Start | After Declaration | Final |
|---|---|---|---|
| fruits | undefined | ["apple", "banana", "cherry"] | ["apple", "banana", "cherry"] |
Indexed array declaration in bash:
fruits=("apple" "banana" "cherry")
Access elements by index: ${fruits[0]}
Indices start at 0
Unassigned indices return empty
Use parentheses to declare arrays