Home> System Tutorial> LINUX> body text

How to solve '/bin/bash^M: bad interpreter' in Linux

WBOY
Release: 2024-06-22 12:00:20
Original
795 people have browsed it

linux解决“/bin/bash^M: bad interpreter“的思路

Reason:

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

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 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!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!