When executing a shell script, the following error is returned:
-bash: ./log_job.sh: /bin/bash^M: bad interpreter: No such file or directory Error causes:
.sh script is written under Windows system, so there may be invisible characters, from the above error prompt, it is very likely that the script file is in DOS format, that is, the end of each line is identified by \r\n, and its ASCII code is 0x0D, 0x0A respectively.
The error that is displayed when executing a shell script is mainly due to the fact that the shell script file is in DOS format, i.e. the end of each line is identified by \r\n, and the end of the UNIX format file is identified by \n.
Special note: ^M is not the ^ and letter M produced by the key shift + 6, it is a character, its ASCII is 0x0D, the way to generate it is to press CTRL+V first, and then enter (or CTRL+M)
solution
There are several ways to check whether the script file is in DOS or UNIX format.
(1) Check the format of the script: cat -A filename From the display results, it can be judged that the file line ending in dos format is ^M$, and the file line ending in unix format is $.
(2) Modify the format of the script: vi filename to open the file and execute:set ff=unixSet the file to unix and execute:wq, saved in UNIX format.
(3) Check the format of the script: cat -A filename From the display result, you can judge that the file line ending in dos format is ^M$, and the file line ending in unix format is $.
|