2

This question already has an answer here:

I have the following prompts

[/share/registrazioni/Script] # cat delete_7gg.sh
#!/bin/sh
find /share/registrazioni/ -type f -mtime +7 -delete
[/share/registrazioni/Script] # which sh
/bin/sh
[/share/registrazioni/Script] # chmod +x delete_7gg.sh
[/share/registrazioni/Script] # ./delete_7gg.sh
-sh: ./delete_7gg.sh: /bin/sh^M: bad interpreter: No such file or directory

why do I get /bin/sh^M: bad interpreter: No such file or directory ? I made the script with vi.

marked as duplicate by Rui F Ribeiro, sourcejedi, mosvy, Ingo Karkat, X Tian Apr 17 at 12:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

8

You seem to have Windows-style line endings (CRLF, ^M^J) instead of unix-style line endings (LF, ^J). Try dos2unix

dos2unix delete_7gg.sh

then run as usual

From man:

dos2unix - DOS/MAC to UNIX text file format converter

Not the answer you're looking for? Browse other questions tagged or ask your own question.