Lists

Lists: Arrays, Associative Arrays: Lists with Names.

Updated

  1. Arrays (Journeyman): An array keeps a list in numbered slots, counted from 0: songs=("Highway Tea" "Window Down") makes one, ${songs[0]} reads a slot, ${#songs[@]} counts the items, songs+=( ) adds one, "${songs[@]}" hands on every item in one piece, and mapfile -t fills an array from a file's lines.
  2. Associative Arrays: Lists with Names (Freelancer): An associative array finds each value by a name instead of a number: declare -A total makes one, total[chill]=15 stores a value under a name, "${!total[@]}" lists the names, and adding to total[$mood] inside a loop keeps a total for every category; it needs bash 4 or newer, which on a Mac means bash 5 from Homebrew.