Languages

Bash - "/bin/bash^M: bad interpreter: No such file or directory" error

3 points
Asked by:
Mark-Rotteveel
537

What is the reason I am getting the following error when I'm trying to run my script under Debian 11?

Error message:

/bin/bash^M: bad interpreter: No such file or directory

I was developing my application under Windows and it was working under Git Bash. After I pushed the repo on Windows and pulled it on Linux my bash script stopped working.

2 answers
6 points
Answered by:
Mark-Rotteveel
537

Use:

dos2unix your-script.sh

 

See also

  1. Debian / Ubuntu - dos2unix installation

0 comments Add comment
3 points
Answered by:
Mark-Rotteveel
537

It looks like Git replaced new line characters to the different ones than Bash requires.

Fix the script file using:

sed -i -e 's/\r$//' your-script.sh

Then run the script file using:

./your-script.sh
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join