bad interpreter — DedSec Project
bad interpreter: inspect the shebang and line endings Recognize the actual failure An executable script begins with ! identifying its interpreter. 'bad interpreter: No such file or…
bad interpreter: inspect the shebang and line endings
Recognize the actual failure
An executable script begins with #! identifying its interpreter. 'bad interpreter: No such file or directory' often means the path after #! does not exist; a carriage return from CRLF can also become part of the interpreter name. The script itself can exist while its interpreter is missing.
Inspect safely before changing anything
head -n 1 script.sh | od -An -tx1
command -v bash
file script.sh
Repair the cause rather than suppressing the warning
Use #!/usr/bin/env bash when env and bash are available and the script deliberately targets Bash. On Termux a hard-coded /bin/bash path from Linux is typically wrong; check command -v bash. Convert CRLF in a copy only after confirming file format. Never run arbitrary downloaded scripts with elevated privileges to bypass the error.
Reference: https://www.gnu.org/software/bash/manual/html_node/Shell-Scripts.html
Determine whether the shebang contains a hidden carriage return
head -n 1 ./demo.sh | cat -v
od -An -tx1 -N40 ./demo.sh
command -v bash
A first line ending in ^M or hex 0d 0a signals CRLF, which can make the system look for /bin/bash\r. Use a proper text editor to save LF line endings and test again; do not blindly strip every carriage return from arbitrary binary files.
Match the runtime, not a copied path
#!/bin/bash may exist on a Linux server but not on Termux. #!/usr/bin/env bash can be more portable when env and bash are both available in the actual environment. Check the first line, the interpreter's location and executable permissions separately. On Windows cmd.exe does not interpret POSIX shebangs directly; use an appropriate shell such as Bash. Compare direct launch with bash demo.sh to distinguish kernel shebang dispatch from parsing of the script body.