解决“/bin/bash^M: bad interpreter: No such file or directory”

Reason: Such an error is prompted when executing the shell script mainly because the shell script file is in dos format, that is, the end of each line is marked with \r\n, while the end of the file in unix format is marked with \n

Solution:

(1) Use the linux command dos2unix filename to directly convert the file to unix format;
(2) Use the sed command sed -i "s/\r//" filename or sed -i "s/^M//" filename to directly replace The terminator is unix format;
(3) vi filename to open the file, execute: set ff=unix to set the file to unix, and then execute: wq to save it in unix format.

There are several ways to check whether the script file is in dos format or unix format.
(1) cat -A filename It can be judged from the displayed results that the line ending of the file in dos format is ^M$, and the line ending of the file in unix format is $;
(2) od -t x1 filename If you see that there is 0d 0a in the output content character, then the file is in dos format, if there is only 0a, it is in unix format;
(3) vi filename to open the file, execute: set ff, if the file is in dos format, it is displayed as fileformat=dos, if it is unxi, it is displayed as fileformat =unix.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324402881&siteId=291194637