Tag Archives: “/bin/bash^M: bad interpreter: No such file or directory”

[Solved] “/bin/bash^M: bad interpreter: No such file or directory”

Reason: when executing a shell script, this error is mainly caused by that the shell script file is in DOS format, that is, the end of each line is marked with a line, while the end of a UNIX file is marked with a line

Solution:

(1) Use the Linux command dos2unix file name to convert the file to UNIX format directly
(2) use the SED command sed – I “s/\ R//” or sed – I “s/^ m//” to directly replace the terminator in UNIX format
(3) VI filename open the file, execute: set FF = UNIX, set the file to UNIX, and then execute: WQ, save it to UNIX format

Several ways to check whether the script file is DOS format or UNIX format
(1) cat – a file name can judge from the display results that the end of the file line in DOS format is ^ m $, and the end of the file line in UNIX format is $
(2) od – t X1 file name if you see 0d 0A characters in the output content, the file is in DOS format, if only 0A, it is in UNIX format
(3) VI filename open the file and execute: set FF. If the file is in DOS format, it will be displayed as fileformat = DOS, if it is uxi, it will be displayed as fileformat = UNIX