views:

135

answers:

2

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.

A: 

Use:

set-buffer-file-coding-system

(should be bound to a key-sequence) before saving the file.

Jürgen Hötzel
+3  A: 

As Jürgen mentioned, you need to use the set-buffer-file-coding-system. You can say

(set-buffer-file-coding-system 'unix)

and stick that into a function inside the find-file-hook so that it will set it for all the buffers you open. Alternatively, you can put it inside the write-file-hook list 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.

Noufal Ibrahim