日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux运行脚本报错:/bin/bash^M: bad interpreter: No such file or directory(dos2unix )(/bin/sh^M)(回车符、换行符)

發布時間:2025/3/20 linux 84 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux运行脚本报错:/bin/bash^M: bad interpreter: No such file or directory(dos2unix )(/bin/sh^M)(回车符、换行符) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

    • origin
    • 20220105 今天在ubuntu上又遇到這個錯誤,差點以為沒遇到過!

origin

如圖,運行一個腳本文件報錯:

原因:

在執行shell腳本時提示這樣的錯誤主要是由于shell腳本文件是dos格式,即每一行結尾以\r\n來標識,而unix格式的文件行尾則以\n來標識

用vi打開腳本文件, 果然!!(20220328 注意,有時用vi打開還看不到^M,但是用后面命令轉換后能解決!)

解決方法,用dos2unix filename命令,,直接把文件轉換為unix格式

果然好了

其他解決方法:

(1)使用linux命令dos2unix filename,直接把文件轉換為unix格式;
(2)使用sed命令sed -i "s/\r//" filename 或者 sed -i "s/^M//" filename直接替換結尾符為unix格式;
(3)vi filename打開文件,執行 : set ff=unix 設置文件為unix,然后執行:wq,保存成unix格式。

查看腳本文件是dos格式還是unix格式的幾種辦法。
(1)cat -A filename
從顯示結果可以判斷,dos格式的文件行尾為^M$,unix格式的文件行尾為$;
(2)od -t x1 filename
如果看到輸出內容中存在0d 0a的字符,那么文件是dos格式,如果只有0a,則是unix格式;
(3)vi filename打開文件,執行: set ff,如果文件為dos格式在顯示為fileformat=dos,如果是unxi則顯示為fileformat=unix。

參考文章:linux解決“/bin/bash^M: bad interpreter“的思路

20220105 今天在ubuntu上又遇到這個錯誤,差點以為沒遇到過!

[root@ubuntu /arnold_test/20220105_crossCompile_x264_ffmpeg/x264]6# ./configure --help bash: ./configure: /bin/bash^M: 解釋器錯誤: 沒有那個文件或目錄

按照先前方法解決吧

可是我用vim或vi打開也看不到^M符號啊??


運行dos2unix指令,發現沒有安裝,于是用apt update和apt install dos2unix安裝了dos2unix,然后運行dos2unix configure,再運行configure --help發現能夠打開了:

[root@ubuntu /arnold_test/20220105_crossCompile_x264_ffmpeg/x264]15# ./configure --help Usage: ./configure [options]Help:-h, --help print this messageStandard options:--prefix=PREFIX install architecture-independent files in PREFIX[/usr/local]--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX[PREFIX]--bindir=DIR install binaries in DIR [EPREFIX/bin]--libdir=DIR install libs in DIR [EPREFIX/lib]--includedir=DIR install includes in DIR [PREFIX/include]--extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS--extra-cflags=ECFLAGS add ECFLAGS to CFLAGS--extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS--extra-rcflags=ERCFLAGS add ERCFLAGS to RCFLAGSConfiguration options:--disable-cli disable cli--system-libx264 use system libx264 instead of internal--enable-shared build shared library--enable-static build static library--disable-bashcompletion disable installation of bash-completion script--enable-bashcompletion force installation of bash-completion script--bashcompletionsdir=DIR install bash-completion script in DIR [auto]--disable-opencl disable OpenCL features--disable-gpl disable GPL-only features--disable-thread disable multithreaded encoding--disable-win32thread disable win32threads (windows only)--disable-interlaced disable interlaced encoding support--bit-depth=BIT_DEPTH set output bit depth (8, 10, all) [all]--chroma-format=FORMAT output chroma format (400, 420, 422, 444, all) [all]Advanced options:--disable-asm disable platform-specific assembly optimizations--enable-lto enable link-time optimization--enable-debug add -g--enable-gprof add -pg--enable-strip add -s--enable-pic build position-independent codeCross-compilation:--host=HOST build programs to run on HOST--cross-prefix=PREFIX use PREFIX for compilation tools--sysroot=SYSROOT root of cross-build treeExternal library support:--disable-avs disable avisynth support--disable-swscale disable swscale support--disable-lavf disable libavformat support--disable-ffms disable ffmpegsource support--disable-gpac disable gpac support--disable-lsmash disable lsmash support[root@ubuntu /arnold_test/20220105_crossCompile_x264_ffmpeg/x264]16#

總結

以上是生活随笔為你收集整理的linux运行脚本报错:/bin/bash^M: bad interpreter: No such file or directory(dos2unix )(/bin/sh^M)(回车符、换行符)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。