|
|
|
Arrays in Bash let you store multiple values in a single variable. Note: Arrays are a Bash feature and are not available in POSIX sh. |
|
|
Create an array with parentheses. |
|
|
Access elements using index (0-based). |
|
|
Get all elements with [@] or [*]. |
|
|
Get the number of elements. |
|
|
Add an element to the end. |
|
|
Set a specific index. |
|
|
Loop over array elements. |
|
|
Loop with indices. |
|
|
Array slicing: ${array[@]:start:length} |
|
|
Get array indices. |
|
|
Check if array is empty. |
|
|
Create array from command output. |
|
|
Delete an element (leaves a gap in indices). |
|
|
Bash 4+
Bash 4+ provides associative arrays (hash maps)
using |
|
|
Iterate over associative array keys: |
|
|
Check if a key exists: |
|
|
Bash 4+ provides |
|
|
Read only first 5 lines: |
|
|
Read from a command using process substitution: |
|
|
Read with a specific delimiter: |
|