Interview Prep/Shell Scripting/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`).

BeginnerTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer

Likely causes → The file has Windows CRLF line endings, so the kernel looks for an interpreter literally named bash\r. It was edited on Windows or committed with core.autocrlf=true.

Diagnose →

file deploy.sh                 # "... with CRLF line terminators"
head -1 deploy.sh | od -c      # shows \r \n at the end

Fix → sed -i 's/\r$//' deploy.sh or dos2unix deploy.sh, then commit the fixed file.

Prevent → Add *.sh text eol=lf to .gitattributes, set the editor to LF for shell files, and run ShellCheck in CI (it reports SC1017 for literal carriage returns).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: syntax, parsing and interpreter errors