#1233·sh

zsh: associative arrays with characters like hyphens or colons in key get mangled

Author: matt-sorensonCreated Dec 12, 2025Updated Sep 7, 2026
Labelshelp wantedzsh

zsh allows hyphens in the keys for associative arrays, but shfmt adds spaces around the hyphens breaking them

Input

foo() {
  local -A dot_parse_opts_errors=()
  dot_parse_opts_errors[too-many-positional]="You may only specify one array name."

  <...>
}

Output

foo() {
  local -A dot_parse_opts_errors=()
  dot_parse_opts_errors[too - many - positional]="You may only specify one array name."

  <...>
}