{"id":287,"date":"2023-02-24T21:52:05","date_gmt":"2023-02-24T13:52:05","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=287"},"modified":"2023-04-30T15:12:37","modified_gmt":"2023-04-30T07:12:37","slug":"shell-script-error-bin-bash-m-bad-interpreter-no-such-file-or-directory","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/24\/shell-script-error-bin-bash-m-bad-interpreter-no-such-file-or-directory\/","title":{"rendered":"shell\u811a\u672c\u62a5\u9519\uff1a\/bin\/bash^M bad interpreter No such file or directory"},"content":{"rendered":"<h2>\u9519\u8bef\u63cf\u8ff0<\/h2>\n<p>\u5177\u4f53\u62a5\u9519\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre><code>[root@localhost test]# .\/test.sh\n-bash: .\/test.sh: \/bin\/bash^M: bad interpreter: No such file or directory<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>\u4e3b\u8981\u539f\u56e0\u662ftest.sh\u662f\u5728windows\u4e0b\u7f16\u8f91\u7136\u540e\u4e0a\u4f20\u5230linux\u7cfb\u7edf\u91cc\u6267\u884c\u7684\u3002<code>.sh<\/code>\u6587\u4ef6\u7684\u683c\u5f0f\u4e3a<code>dos<\/code>\u683c\u5f0f\u3002\u800clinux\u53ea\u80fd\u6267\u884c\u683c\u5f0f\u4e3a<code>unix<\/code>\u683c\u5f0f\u7684\u811a\u672c\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7vi\u7f16\u8f91\u5668\u6765\u67e5\u770b\u6587\u4ef6\u7684format\u683c\u5f0f\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>\uff081\uff09\u9996\u5148\u7528vim\u547d\u4ee4\u6253\u5f00\u6587\u4ef6<\/p>\n<pre><code>[root@localhost test]# vim test.sh<\/code><\/pre>\n<p>\uff082\uff09\u5728vim\u547d\u4ee4\u6a21\u5f0f\u4e2d\u4f7f\u7528 <code>:set ff<\/code> \u547d\u4ee4<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u6587\u4ef6\u7684\u683c\u5f0f\u4e3ados<\/p>\n<h2>\u4fee\u6539\u6587\u4ef6format\u4e3aunix<\/h2>\n<p>\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528vi\u4fee\u6539\u6587\u4ef6format<\/p>\n<p>\u547d\u4ee4\uff1a<code>set ff=unix<\/code><\/p>\n<p>\u65b9\u6cd5\u4e8c\uff1a\u76f4\u63a5\u4f7f\u7528dos2unix\u547d\u4ee4\u4fee\u6539<\/p>\n<pre><code>[root@localhost test]# dos2unix test.sh\ndos2unix: converting file test.sh to UNIX format ...<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9519\u8bef\u63cf\u8ff0 \u5177\u4f53\u62a5\u9519\u4fe1\u606f\u5982\u4e0b\uff1a [root@localhost test]# .\/test.sh -bash:  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[89],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-shell"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=287"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}