/errors/bash/script-cannot-execute-required-file-not-found
bash: ./script.sh: cannot execute: required file not found
verified onenvironmentlocal · linux 6.18.44-fc-v140 x64 · GNU bash 5.2.21updated
- tool
- Bash
- exit code
- 127
- versions
- bash 5.x
- os
- linux, macos
cannot execute: required file not found (older bash: bad interpreter: No such file or directory) means the kernel could not start the program named in the first line. For a script created on Windows the cause is usually the invisible \r at the end of #!/bin/bash: the system looks for an interpreter called /bin/bash\r. Convert the file to LF line endings.
Reproduce it
The exit status is 127. The exact wording depends on the bash version.
printf '#!/bin/bash\r\necho hi\r\n' > crlf.sh
chmod +x crlf.sh
./crlf.shOutput · exit 127
bash: line 3: ./crlf.sh: cannot execute: required file not found
Confirm the carriage returns:
printf '#!/bin/bash\r\necho hi\r\n' > crlf.sh
head -n 1 crlf.sh | od -c | head -n 2Output
0000000 # ! / b i n / b a s h \r \n 0000015
Fix it
printf '#!/bin/bash\r\necho hi\r\n' > crlf.sh
chmod +x crlf.sh
sed -i 's/\r$//' crlf.sh
./crlf.shOutput
hi
If the file already has LF endings, check that the interpreter exists: head -n 1 script.sh, then ls -l on that path. Alpine images have no /bin/bash until bash is installed; use #!/bin/sh for POSIX scripts.
Sources
Related pages
errors · bashbash: ./script.sh: Permission deniedbash prints Permission denied (exit 126) when a script has no execute bit or sits on a noexec mount. Run chmod +x script.sh, or start it with bash script.sh.errors · bashbash: command not found (exit status 127)bash prints "command not found" and exits with status 127 when a command is not in PATH, not installed or misspelled. Check with command -v and fix PATH.errors · bashbash: syntax error near unexpected tokenbash prints this when its parser meets an unexpected word: a missing then, do or semicolon, unquoted parentheses, or CRLF line endings. Causes and fixes.