Interview Prep/Shell Scripting/Troubleshooting: syntax, parsing and interpreter errors

On a Mac, `declare -A config` fails with `declare: -A: invalid option`.

IntermediateTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer

Likely causes → macOS ships Bash 3.2 (2007) at /bin/bash, which has no associative arrays (added in Bash 4.0). The shebang is #!/bin/bash or the user's PATH finds the old Bash first.

Diagnose →

bash --version | head -1
head -1 script.sh

Fix → brew install bash, use #!/usr/bin/env bash, and make sure /opt/homebrew/bin comes before /bin in PATH. Add a version guard: (( BASH_VERSINFO[0] >= 4 )) || { echo "need Bash 4+" >&2; exit 1; }.

Prevent → Document the minimum Bash version and test in CI on macOS if laptops are a target.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: syntax, parsing and interpreter errors