Such an error is prompted when executing a shell script mainly because the shell script file is in dos format, that is, the end of each line is identified by rn, while the end of the line of the file in unix format is identified by n
(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 ending character with the unix format;
(3) Open the file with vi filename, execute: set ff=unix to set the file to unix, and then execute: wq to save it in unix format.
Several ways to check whether a script file is in dos format or unix format.
(1) cat -A filename It can be judged from the display results that the file line ending in dos format is ^M$, and the line ending in unix format file is $;
(2) od -t x1 filename If you see the characters 0d 0a in the output content, then the file is in dos format. If there is only 0a, it is in unix format;
(3) Open the file with vi filename and execute: set ff. If the file is in dos format, it will be displayed as fileformat=dos. If it is unxi, it will be displayed as fileformat=unix.
The above is the detailed content of How to solve '/bin/bash^M: bad interpreter' in Linux. For more information, please follow other related articles on the PHP Chinese website!