# Shell Advanced Features ## Indexed Arrays Arrays store multiple values in a single variable. Declare with `arr=(val1 val2 val3)` or assign individual elements. ```bash # Declare array colors=("red" "green" "blue") # Access by index (zero-based) echo ${colors[0]} # Output: red echo ${colors[2]} # Output: blue # Assign individual elements colors[3]="yellow" # Get all elements echo ${colors[@]} # Output: red green blue yellow # Get array length echo ${#colors[@]} # Output: 4 # Iterate over array for color in "${colors[@]}"; do echo "$color" done ``` Use associative arrays (hash maps) with `declare -A` for key-value pairs: ```bash # Declare associative array declare -A config config[host]="localhost" config[port]="8080" config[user]="admin" # Access by key echo ${config[host]} # Output: localhost # Iterate over keys and values for key in "${!config[@]}"; do echo "$key = ${config[$key]}" done ``` ## Here Documents Pass multi-line text to stdin using `<