在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory。这是不同系统编码格式引起的:在windows系统中编辑的.sh文件可能有不可见字符,所以在Linux系统下执行会报以上异常信息。

如果我们的脚本是在windows环境下编写的,需要将编码转换称unix格式。

下面我们用Notepad++中Windows,Unix,Mac三种格式之间的转换。

1.我们先查看当前文件格式(换行符用的是什么字符),如图:

linux sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory

 

 2.从Windows转换为Unix/Linux格式:

linux sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-09-17
  • 2022-01-16
  • 2022-12-23
猜你喜欢
  • 2021-06-30
相关资源
相似解决方案