运行shell脚本报错```$'\r':command not found```

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运行shell脚本报错```$'\r':command not found```相关的知识,希望对你有一定的参考价值。

参考技术A

在window系统改了脚本,传输到Linux上执行。脚本在window编辑器下,每行结尾是\\r\\n 的Unix 结果行是\\n。所以在Linux下运行脚本 会任务\\r 是一个字符,所以运行错误

需要把文件转换下:

使用Notepad++, Edit -> EOL conversion -> Unix/OSX format(编辑->文档格式转换->转为Unix)

参考
[1] bash - \'\\r\': command not found - .bashrc / .bash_profile - Stack Overflow

shell脚本 运行 报错 /bin/bash^M: bad interpreter: 没有那个文件或目录

原因:

Linux和Windows 文件格式兼容问题

解决:

查看当前文件格式:

vim fileName 打开文件

:set ff? 查看当前文档是什么格式

eg: fileformat=unix

:set ff=unix 设置为linux格式

以上是关于运行shell脚本报错```$'\r':command not found```的主要内容,如果未能解决你的问题,请参考以下文章

shell脚本运行报错$' ': command not found

Linux-006-执行Shell脚本报错 $' ':command not found

shell脚本中一些特殊符号都有哪些

LoadRunner跑脚本时报错

如何运行shell脚本

shell命令-e未找到命令