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

`mapfile: command not found` on one machine but not another.

IntermediateTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer

Likely causes → Bash older than 4.0 (macOS 3.2), or the script is not running under Bash at all (zsh, dash, ash), where mapfile/readarray do not exist.

Diagnose → echo "$BASH_VERSION" inside the script (empty means not Bash).

Fix → Run with Bash 4+; for portability, replace with a read loop: arr=(); while IFS= read -r l; do arr+=("$l"); done < <(cmd).

Prevent → Version guard at the top of scripts that use Bash 4 features.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: syntax, parsing and interpreter errors