Arrays & String Manipulation

Indexed and associative arrays, and parameter expansion for slicing, replacing and defaults.

Bash has arrays and dictionaries, and a compact syntax (parameter expansion) for common string operations — removing extensions, replacing text, taking substrings — without calling external programs.

Arrays and string operations

boards=(...) creates an array; += appends; "${boards[@]}" expands to every element as a separate word.

declare -A creates an associative array (key → value); "${!owner[@]}" lists the keys.

${file%.bin} removes a suffix, ${file#firmware-} a prefix, ${file/a/b} replaces, ${file:9:6} takes a substring.

IFS=. read -r major minor patch <<< "$version" splits a string into variables.

${BAUD:-115200} uses a default when the variable is unset or empty.

Reference

for b in ${boards[*]}; do for b in "${boards[@]}"; do Only the quoted [@] form keeps each element as one item when elements contain spaces.

How do you get 'report' from file=report.tar.gz?

${file%%.*} (removes the longest suffix starting with a dot).