文章目录
origin2025 今天在ubuntu上又遇到这个错误,差点以为没遇到过!origin
如图,运行一个脚本文件报错:
原因:
在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识
用vi打开脚本文件, 果然!!(0328 注意,有时用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“的思路
2025 今天在ubuntu上又遇到这个错误,差点以为没遇到过!
[root@ubuntu /arnold_test/2025_crossCompile_x264_ffmpeg/x264]6# ./configure --helpbash: ./configure: /bin/bash^M: 解释器错误: 没有那个文件或目录
按照先前方法解决吧
可是我用vim或vi打开也看不到^M
符号啊??
运行dos2unix
指令,发现没有安装,于是用apt update
和apt install dos2unix
安装了dos2unix
,然后运行dos2unix configure
,再运行configure --help
发现能够打开了:
[root@ubuntu /arnold_test/2025_crossCompile_x264_ffmpeg/x264]15# ./configure --helpUsage: ./configure [options]Help:-h, --helpprint this messageStandard options:--prefix=PREFIXinstall 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-sharedbuild shared library--enable-staticbuild 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-interlaceddisable 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/2025_crossCompile_x264_ffmpeg/x264]16#
linux运行脚本报错:/bin/bash^M: bad interpreter: No such file or directory(dos2unix )(/bin/sh^M)(回车符 换行符)