This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12633|Reply: 0

[linux] /bin/bash^M: bad interpreter: No such file or directory

[Copy link]
Posted on 6/13/2020 10:40:35 PM | | | |
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 $.







Previous:SSIS Tutorial 1 Introduction to SQL Server Integration Services
Next:Nginx log splitting and deletion
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com