A script saved with Windows CRLF line endings embeds a literal carriage return in the shebang: the kernel looks for /bin/bash^M, which doesn't exist. Convert the file and fix git so it never happens again.
git's core.autocrlf=true on Windows, or a Windows editor, wrote . The shebang line /bin/bash makes the kernel search for an interpreter named bash plus a carriage return. cat -A shows the ^M characters immediately.
cat -A script.sh | head -3 # ^M at line ends = CRLF
sed -i 's/
$//' script.sh # or: dos2unix script.sh
# .gitattributes in repo root: * text=auto eol=lf — and *.sh specifically: *.sh text eol=lf
# git add --renormalize . && git commit -m 'normalize line endings'
The ^M in the error message IS the diagnosis — the interpreter path contains a carriage return, which can only come from a CRLF file. .gitattributes beats autocrlf settings for shared repos: it lives in the repo and normalizes every contributor identically, regardless of their local git config.
The Windows checkout introduced the CRLF; Linux build containers faithfully copy it in. Developers on Linux/macOS with LF defaults never trigger it — a classic works-on-my-machine.
It only strips CR characters at line ends (or converts as directed). Content, permissions, and everything else are untouched — safe on scripts, config files, and source.
Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.
Browse the template store →One-time. Yours to modify. Instant download from the NinjaOps template store.