linux shell 报错 bad interpreter No such file or directory

最近在 linux 使用 ndk 编译一些东西,就使用到了 shell 脚本,结果在执行的时候出现:

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

使用 vim 打开 shell 脚本,发现并没有问题,最后发现是由于 shell 脚本在 windows 下编写的,copy 到 linux 后文本格式不对,所以只需要更改一下文本格式就可以了,用 vim 打开 shell 脚本,在命令行模式下:

:set fileformat=unix

最后保存退出就可以执行了。