Array Basics
In this page:
Array Basics
Bash arrays store multiple values in a single variable, declared with name=(value1 value2 value3). Individual elements are accessed with ${name[index]}, using zero-based indexing. Arrays are one of the few compound data structures Bash offers natively.
Note: Always quote array expansions, like "${arr[@]}", to keep elements with spaces intact.
Example: Array Basics
#!/bin/bash
fruits=("apple" "banana" "cherry")
echo "First fruit: ${fruits[0]}"
echo "Second fruit: ${fruits[1]}"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: