How does Bash handle a script with Windows line endings (CRLF)?
IntermediateConceptShells, scripts and execution
Answer
Every line ends in \r, which Bash treats as part of the last word. The shebang becomes bash\r, so ./s.sh fails with bad interpreter: No such file or directory, and bash s.sh fails with $'\r': command not found or syntax error near unexpected token $'\r'.
file deploy.sh # "with CRLF line terminators"
sed -i 's/\r$//' deploy.sh # or: dos2unix deploy.sh
Prevent it with *.sh text eol=lf in .gitattributes.
More on Shells, scripts and execution
What is a shell, and how is Bash different from sh, dash and zsh?BeginnerWhat does the shebang line do, and why prefer `#!/usr/bin/env bash` over `#!/bin/bash`?BeginnerWhat is the difference between `./script.sh`, `bash script.sh` and `source script.sh`?BeginnerWhat happens when you type a command name? How does Bash decide what to run?AdvancedWhy must `cd`, `export` and `read` be builtins rather than external programs?IntermediateWhat is the difference between a login, interactive and non-interactive shell, and which startup files run?Intermediate