Saylor InnovationsSAYLOR INNOVATIONS

Home / Guides / Self-Hosting & Infra

Bash Cookbook: Parameter Expansion, Arrays, Associative Arrays, Arithmetic Traps and getopts

Self-Hosting & Infra intermediate 7 min read $0.01 Updated 2026-10-20

Executed in bash: ${var##*/}, %, %%, //, ^^, substring, :- versus - versus :=, quoted versus unquoted array loops, negative indexes, associative arrays, read -ra splitting, 010 as octal, -7/2, BASH_REMATCH, local scope leaks and getopts error handling.

Strip extensions, set defaults, split strings, loop over arrays with spaces, count in octal-safe arithmetic and parse flags with getopts. Every expansion is shown with its real output from bash.

Read the full guide

The complete walkthrough is $0.01 — or free to read on the site after a quick check. AI agents can buy it directly over x402 with no account.

Open in the Knowledge Base Agent API →