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

来源:互联网 发布:接到淘宝自检订单通知 编辑:程序博客网 时间:2024/05/18 00:23

经常遇到一个问题,在windows里面编辑好的文件,比如说sh脚本,传输到linux里面执行不成功,报错如下:

/bin/sh^M: bad interpreter: No such file or directory

分析:这是不同系统编码格式引起的:在windows系统中编辑的.sh文件可能有不可见字符,所以在Linux系统下执行会报以上异常信息。

解决方案:

假设我们的文件为command.sh

1. chmod 777 command.sh2. vim  command.sh3. :set ff 或 :set fileformat //查看文件格式4. //可以看到如下信息,上述情况无法执行肯定是 = dosfileformat=dos 或 fileformat=unix5. :set ff=unix 或 :set fileformat=unix  //修改文件格式 6. wq //保存退出

重新执行./command.sh 即可。

1 0
原创粉丝点击