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.
More on Troubleshooting: syntax, parsing and interpreter errors
`./deploy.sh` fails with `bash: ./deploy.sh: /bin/bash^M: bad interpreter: No such file or directory` (or, on Bash 5.2, `cannot execute: required file not found`).Beginner`bash: ./backup.sh: Permission denied` right after cloning the repo.Beginner`deploy.sh: line 14: syntax error near unexpected token `fi'`Beginner`install.sh: line 87: syntax error: unexpected end of file`Beginner`warning: here-document at line 12 delimited by end-of-file (wanted `EOF')` and the rest of the script never runs.Beginner`bash: [: missing `]'`Beginner