files=(a.txt b.txt c.txt)Whitespace separates elements unless quoted.
Indexed and associative arrays, string handling, read/mapfile, and common Bash text-processing patterns.
Create, inspect, and modify indexed arrays.
files=(a.txt b.txt c.txt)Whitespace separates elements unless quoted.
echo "${files[1]}"Array indexes are zero-based.
printf '%s
' "${files[@]}"Use "${array[@]}" to preserve element boundaries.
echo "${#files[@]}"Very common in loops and validation.
files+=(d.txt)Works cleanly for indexed arrays.
for f in "${files[@]}"; do echo "$f"; doneAlways quote "${array[@]}" in loops.
unset 'files[1]'Remaining indexes are preserved; arrays can be sparse.
Use key/value maps in Bash.
declare -A ports=([http]=80 [https]=443)Requires Bash 4 or newer.
echo "${ports[https]}"Associative arrays are ideal for lightweight maps.
printf '%s
' "${!ports[@]}"Useful for loops and reporting.
for k in "${!ports[@]}"; do echo "$k=${ports[$k]}"; doneOrder is not guaranteed.
Case conversion, trimming, splitting, and joins.
name='Hello World'
echo "${name,,}"Bash supports case modification operators on parameters.
name='Hello World'
echo "${name^^}"Useful for normalization and IDs.
url='https://example.com'
echo "${url#https://}"Pattern-based trimming is faster than spawning external tools.
file='archive.tar.gz'
echo "${file%.gz}"Useful for extensions and temporary suffixes.
IFS=, read -r -a parts <<< 'red,green,blue'
printf '%s
' "${parts[@]}"Use IFS carefully because it affects word splitting.
(IFS=,; echo "${parts[*]}")The subshell limits IFS changes to one command group.
read, mapfile, and input handling patterns.
read -r -p 'Enter name: ' name-r prevents backslash escaping during input.
read -r -s -p 'Password: ' password; echoCommon for credentials in interactive scripts.
mapfile -t lines < file.txtmapfile and readarray are Bash builtins.
IFS=: read -r user shell <<< 'root:/bin/bash'
echo "$user $shell"Useful for colon, comma, or tab-separated data.