1,684   Shell

今天在写shell时遇到以下报错

Syntax error: word unexpected (expecting "do")

google一番,可能是因为在Windows上编辑的,放到linux服务器上执行会出现字符格式报错,或者直接粘贴shell也会导致这种情况出现。

还有另外一个报错

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

这是因为Notepad++编码会加上BOM,需要在Encoding选择without-BOM

在window上编辑脚本到Linux上运行,最好经过转义,通过 dos2unix 来实现转义

我是在Ubuntu上遇到的问题,系统没有 dos2unix ,需要自行安装

sudo apt-get install dos2unix 

然后,转义命令

dos2unix test.sh



Leave a Reply

Your email address will not be published. Required fields are marked *