Syntax error: word unexpected (expecting “do”)
- 我将shell脚本先写到文本txt中,然后进入linux环境修改为sh文件。
- 在运行sh examples/myfile/create_filelist.sh 时,出现错误:
- Syntax error: word unexpected (expecting “do”)
首先:
hexdump -C examples/myfile/create_filelist.sh
然后:
cat examples/myfile/create_filelist.sh | tr -d '\r' >> examples/myfile/create_filelist1.sh
最后再运行新的脚本:成功啦O(∩_∩)O~
sh examples/myfile/create_filelist1.sh
- 打开看下两个文件的txt对比:
更简单的一种方法:vim打开这个出错文件然后输入下面这条命令,然后就可以执行了。
总结:出错原因,windows里的换行是\n,而linux中是\r,修改下编码就可以了。
/usr/bin/env: sh: No such file or directory when running command play
- 出现这个问题的原因可能是因为你在windows下面写的文件,然后在linux下运行,根据上面那个修改就可以了;