While running a script in a rails app, I got this error /usr/bin/ruby^M: bad interpreter: No such file or directory in the shebang line of the script.
One of the fixes that I came across after a bit of googling is to add a harmless switch at the end of the line; in this case a -w (which turns warnings on in the script). Even though it worked, the log file started growing with all kinds of warnings which obviously I don’t want to live with.
More search revealed that it’s actually a pesky file format issue (damn the ^M). A quick change in the file format to unix did the trick. In vim, do :set ff=unix to achieve this and remove the bad interpreter error!