Skip to content


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

So, you just uploaded a bash script to your server, its first line is #!/bin/bash, and when you run it it stops with an error /bin/bash^M: bad interpreter: No such file or directory? You’ve probably created the file on Windows, using Windows line breaks, which apparently .sh scripts can’t handle properly. You’ll need to convert your line breaks to UNIX format. This can’t be done in Notepad (but hopefully you’re not using that), however it can be done in Notepad++, only it’s remarkably well hidden IMO. The menu item to look for is simply Edit → EOL conversion (EOL standing for end of line). Just pick the right format (it should indicate that you have Windows line breaks, just switch to UNIX line breaks).

Alternatively, you could also run dos2unix yourscript.sh right on your server, although that’s something I found in some pretty old thread, and on Debian 7 at least this dos2unix thing doesn’t seem to be installed by default.

On a side note, I encountered this issue while copy/pasting this nice anti-w00tw00t scan script from spamcleaner.org.

Posted in Linux, programming.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Akhmad Ghozali says

    Run following command in terminal

    sed -i -e ‘s/\r$//’ scriptname.sh

    Then try

    ./scriptname.sh

    It should work.

    Ref: https://stackoverflow.com/a/29747593



Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA