The main reason for this error when executing shell scripts is that the shell script file is in DOS format, that is, the end of each line is identified by \ r \ n, and the end of the file line in UNIX format is identified by \ n.
There are several ways to see if the script file is in DOS or UNIX format.
(1) cat-a filename from the display results can be judged that the DOS format of the file line tail for the ^m$,unix format of the file line end is $.
(2) od-t x1 filename If you see 0d 0a characters in the output, the file is in DOS format, and if only 0a is the UNIX format.
(3) VI filename Open file, execute: Set FF, if the file is in DOS format shown as Fileformat=dos, if Unxi is displayed as Fileformat=unix.
Workaround:
(1) using the Linux command Dos2unix filename to convert files directly to UNIX format
(2) Use the SED command sed-i "s/\r//" filename or sed-i "s/^m//" filename to replace the end character directly with the UNIX format
(3) VI filename Open file, execute: Set Ff=unix set file for Unix, then execute: WQ, save to UNIX format.
Resolve "/bin/bash^m:bad interpreter:no such file or directory"