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

Running `bash script.sh` prints `script.sh: line 2: $'\r': command not found` on every blank line.

BeginnerTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer

Likely causes → CRLF line endings again. Running through bash avoids the shebang error, but every blank line now contains just \r, which Bash tries to run as a command. Other lines may fail subtly (cd /srv/app\r → No such file or directory).

Diagnose → cat -A script.sh | head shows ^M$ at line ends.

Fix → sed -i 's/\r$//' script.sh.

Prevent → .gitattributes with *.sh text eol=lf; an .editorconfig with end_of_line = lf.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: syntax, parsing and interpreter errors