shell报错:/bin/sh^M: bad interpreter: No such file or directory
在windows环境下写了个shell脚本,然后在linux下运行的时候,发现并不能正常运行,而且是已经在使用命令 chmod 777 xxx.sh了,结果发现是shell脚本格式出了错误。
测试shell
#!/bin/sh
echo "test shell"运行,报错
[root@localhost]# ./test.sh
-bash: ./test.sh: /bin/sh^M: bad interpreter: No such file or directory原因
test.sh 是在windows下进行编辑然后上传到linux下的,windows下与linux下的编码不一致。
.sh文件的格式为dos格式。而linux只能执行格式为unix格式的脚本
解决方法
使用vi命令打开文件
vi test.sh在vi命令模式下(就是我们刚使用命令打开的模式)查看格式
: set ff在刚才的:set ff模式下我们可以看到fileformat=dos格式
dos格式是windows所有的,这时候我们需要把格式改为linux所识别的unix格式
修改unix格式
使用命令:
:set ff=unix文章整理来自:https://blog.csdn.net/xudailong_blog/article/details/82891506
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
小菜鸡
评论已关闭