经常遇到一个问题,在windows里面编辑好的文件,比如说sh脚本,传输到linux里面执行不成功,报错如下:
/bin/sh^M: bad interpreter: No such file or directory
分析:这是不同系统编码格式引起的:在windows系统中编辑的.sh文件可能有不可见字符,所以在Linux系统下执行会报以上异常信息。
解决方案:
假设我们的文件为command.sh
1. chmod 777 command.sh
2. vim command.sh
3. :set ff 或 :set fileformat //查看文件格式
4. //可以看到如下信息,上述情况无法执行肯定是 = dos
fileformat=dos 或 fileformat=unix
5. :set ff=unix 或 :set fileformat=unix //修改文件格式
6. wq //保存退出
重新执行./command.sh 即可。