from
http://myswirl.blog.163.com/blog/static/51318642201192381444842/
Execute .sh script in Linux, exception /bin/sh^M: bad interpreter: No such file or directory
Analysis: This is caused by different system encoding formats. The .sh file edited in the Windows system may have invisible characters, so the above exception information will be reported when executed under the Linux system.
Solution: 1. Use some editors such as UltraEdit or EditPlus to convert the script code
under Windows , and then put it into Linux for execution.
The conversion method is as follows (UltraEdit): File-->Conversions-->DOS->UNIX.
2 Converting in Linux
2.1 First make sure the file has executable permissions
#sh>chmod a+x filename
2.2 Then modify the file format
#sh>vi filename
2.3 Use the following command to view the file format
: set ff or: set fileformat
You can see the following Information
fileformat=dos or fileformat=unix
2.4 Use the following command to modify the file format
: set ff=unix or: set fileformat=unix
:wq (save and exit)
2.5 Finally execute the file
#sh>./filename