in Linux

执行shell脚本错误‘.sh file: /bin/bash^M: bad interpreter’

问题

执行一个shell脚本返回错误:Not able to execute a .sh file: /bin/bash^M: bad interpreter,发现是从Windows系统拷贝去Linux系统,回车换行符导致。需要将行结尾修改成Line feeder.

解决

sed -i -e 's/\r$//' script.sh

或者用vi编辑器打开:

“`shel;
:set ff=unix
:wq

<pre><code class="">或者:
“`shell
:%s/^M//gc

参考

Not able to execute a .sh file: /bin/bash^M: bad interpreter

Write a Comment

Comment