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

Under `sh`, the script fails with `Syntax error: "(" unexpected`.

IntermediateTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer

Likely causes → Bash-only syntax parsed by dash: an array assignment hosts=(a b c), function name() {, or <(...) process substitution (which gives Syntax error: redirection unexpected instead).

Diagnose → shellcheck -s sh script.sh lists each bashism with the line number; checkbashisms script.sh does the same.

Fix → Run it with Bash (fix the shebang or invocation), or port: arrays to set -- a b c or newline-separated strings, function f() to f(), process substitution to a temp file.

Prevent → Decide per script: Bash with an explicit shebang, or POSIX sh checked with shellcheck -s sh.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: syntax, parsing and interpreter errors