bash问题:syntax error near unexpected token `elif'

linux 执行脚本出现如下错误:

***.sh: line 2: $'\r': command not found
***.sh: line 4: $'\r': command not found
***.sh: line 8: $'\r': command not found
***.sh: line 12: $'\r': command not found
***.sh: line 18: syntax error near unexpected token `elif'
***.sh: line 18: `  elif [ "..." ]; then

google出的解决方法(对.sh文件中内容进行替换):

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

原文链接:

https://unix.stackexchange.com/questions/97157/command-not-found-and-syntax-error-near-unexpected-token

网上说的在notepad++中打开所有的回车换行都是windows的CR LF,然而我的打开本来就是unix的LF方式,所以不是这个问题。使用dos2unix等工具不知道可不可以解决,感觉太复杂。

发布了17 篇原创文章 · 获赞 2 · 访问量 7542

猜你喜欢

转载自blog.csdn.net/youshiwukong1524/article/details/83507466