The shebang specifies an invalid path

SC2239: the interpreter path in the shebang is not an absolute path. Use /usr/bin/env or an absolute path like /bin/bash.

Problem

The kernel requires the interpreter path in a shebang to be an absolute path. A relative path like `#!bash` or `#!./bash` will fail with "bad interpreter" because the kernel does not search PATH or resolve relative paths when execing the interpreter.

Bad

#!bash              # relative, not on PATH for kernel
#!./local/bash        # relative path

Good

#!/usr/bin/env bash
#!/bin/bash
#!/usr/local/bin/bash

Explanation

Use `#!/usr/bin/env bash` for portability — env searches PATH and works even when Bash lives in non-standard locations. Use `#!/bin/bash` only when you are certain the path exists on every target system.

Related

SC2148

SC2096

When It Matters

The shebang must be an absolute path to a real executable. #!/bin/bash on a system where Bash lives in /usr/local/bin (FreeBSD, NixOS, some minimal containers) produces "bad interpreter: No such file or directory" — a confusing error that looks like the script itself is missing. A space before the #!, a leading blank line, or a Windows CRLF line ending breaks it just as thoroughly, and the CRLF case produces the notorious error message with an invisible carriage return in it.

Second Example

Note

Use #!/usr/bin/env bash for Bash scripts and #!/bin/sh only when the script is truly POSIX; /bin/sh is dash on Debian and Ubuntu and does not support Bash syntax.

Exceptions

A hardcoded /bin/bash is fine for scripts that will only ever run on a controlled image where that path is guaranteed, and it is marginally safer in setuid contexts because it does not consult PATH. Note the assumption in a comment so nobody ports the script and loses an afternoon to the error message.

Faq

Q

Why does my script say "bad interpreter" when the file clearly exists?

A

Almost always CRLF line endings: the kernel looks for an interpreter named "bash\r". Convert the file to LF endings and it runs.

Q

Can I pass options in the shebang?

A

One argument at most is portable, and with env even that is unreliable on older systems. Put set -euo pipefail on the first line of the body instead of #!/usr/bin/env bash -e.

Q

Does the shebang matter if I run "bash script.sh"?

A

No — invoking the interpreter explicitly bypasses the shebang entirely. It matters when the script is executed directly, which is how everything else will run it.