CentOS6 Shell script /bin/bash^M: bad interpreter error solution

Save a script file under windows, upload it to centos with ssh, add permission to execute nginx and prompt that there is no such file or directory.
The shell script is placed in the /etc/init.d/ directory, and then executes /etc/init.d/nginx, and it prompts the sentence /bin/bash^M: bad interpreter.
I found information on the Internet to know that
if this script has been edited under Windows, it may be converted into the dos text format under Windows. In this format, the end of each line is marked with \r\n, and its ASCII code They are 0x0D, 0x0A respectively. If you put this script file directly on Linux, it will report /bin/bash^M: bad interpreter error message.
The solution is very simple. First, you need to check to see if your script file is caused by this problem. Use the vi command to open the script file to be checked, and then use the
:set ff?
command to check to see if it is the word dos. , if it is in dos format, continue to execute
: set ff=unix
and then execute
: qw
to save and exit.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327043667&siteId=291194637