您的位置:首页 > 运维架构 > Shell

:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory(转)

2018-01-09 14:33 519 查看
我在windows下用notepad++编写了一个shell 脚本,该脚本在执行时报错,报错信息为:

[root@localhost test]# ./test.sh
-bash: ./test.sh: /bin/sh^M: bad interpreter: No such file or directory


原因:是在windows下编辑时.sh文件的格式为dos格式,该格式下有些不可见字符。而linux只能执行格式为unix格式的脚本。

解决办法有两个:

方法一:使用vi编辑器来修改文件格式。

1.首先用vi命令打开文件

Shell代码

[root@localhost test]# vi test.sh


2.在vi命令模式中使用
:set ff
命令,可以看到该文件的格式为dos

fileformat = dos


3.修改文件format为unix

命令:
set ff=unix


执行完后再通过set ff命令查看文件格式,结果如下:

fileformat = unix


方法二:使用dos2unix命令修改文件格式。

[root@localhost test]# dos2unix test.sh
dos2unix: converting file test.sh to UNIX format ..


OK啦!

转自:http://chenzhou123520.iteye.com/blog/1832890
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐