I have to use windows to write some shell scripts. I decided to use emacs, but I get a weird error when running the script:
/bin/bash^M: bad interpreter: No such file or directory
Correct me if I’m wrong, but that looks like the shebang ends in \r\n instead of just \n. How can I tell emacs to only write \n? I’m in Shell-script major mode. It’s quite surprising this isn’t fixed by default.
As Jürgen mentioned, you need to use the
set-buffer-file-coding-system. You can sayand stick that into a function inside the
find-file-hookso that it will set it for all the buffers you open. Alternatively, you can put it inside thewrite-file-hooklist so that the file-coding-system is set properly before you dump the file to disk.For a simpler way out, if you’re using the GUI version of Emacs, you can click on the 3rd character in the modeline from the left. It’s to toggle between eol formats.