Skip to content

/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.

bash
printf '#!/bin/bash\r\necho hi\r\n' > crlf.sh
chmod +x crlf.sh
./crlf.sh

Output · exit 127

bash: line 3: ./crlf.sh: cannot execute: required file not found

Confirm the carriage returns:

bash
printf '#!/bin/bash\r\necho hi\r\n' > crlf.sh
head -n 1 crlf.sh | od -c | head -n 2

Output

0000000   #   !   /   b   i   n   /   b   a   s   h  \r  \n
0000015

Fix it

bash
printf '#!/bin/bash\r\necho hi\r\n' > crlf.sh
chmod +x crlf.sh
sed -i 's/\r$//' crlf.sh
./crlf.sh

Output

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