Shell script CRLF shebang "No such file or directory" in CI
The script has Windows CRLF line endings, so the shebang line ends in \r. The kernel reads the interpreter as /bin/bash\r, which does not exist, and reports "No such file or directory" even though bash is installed.
What this error means
Running ./script.sh fails with "bad interpreter: No such file or directory", or a \r: command not found error appears on later lines. The file was authored or committed on Windows.
./deploy.sh: line 2: $'\r': command not found
env: bash\r: No such file or directoryCommon causes
CRLF line endings from a Windows editor
The file was saved with \r\n. The \r at the end of the shebang is treated as part of the interpreter name, so the lookup fails.
Git re-added CRLF on checkout
A .gitattributes or core.autocrlf setting converted the shell script to CRLF when the runner checked it out.
How to fix it
Convert the file to LF
- Strip carriage returns with
sedordos2unix. - Re-run the script to confirm the interpreter resolves.
- Commit the LF version.
sed -i 's/\r$//' deploy.sh
# or: dos2unix deploy.shForce LF for shell scripts in git
Add a .gitattributes rule so shell scripts are always checked out with LF, regardless of the developer OS.
*.sh text eol=lfHow to prevent it
- Commit a
.gitattributesenforcingeol=lffor*.sh. - Configure editors to use LF for shell scripts.
- Run
file script.shorcat -Ato spot^Mbefore committing.