windows上写的脚本,直接拷贝到linux系统上运行可能会出现格式不兼容问题。
情景还原:
在pycharm中远程编辑linux服务器的代码,编写了一个shell脚本,在服务器运行sh脚本时报错:
/bin/bash^M: bad interpreter: No such file or directory
解决办法:
-
比如文件名为myshell.sh,vim myshell.sh
-
执行vim中的命令 : set ff?查看文件格式,如果显示fileformat=dos,证明文件格式有问题
-
执行vim中的命令 :set fileformat=unix 将文件格式改过来就可以了,然后:wq保存退出就可以了