意外令牌“完成"附近的BASH语法错误 [英] BASH Syntax error near unexpected token 'done'
本文介绍了意外令牌“完成"附近的BASH语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么问题的想法吗?
我的代码是:
#!/bin/bash
while :
do
echo "Press [CTRL+C] to stop.."
sleep 1
done
将其另存为.sh并运行bash file.sh
Saved it as .sh and ran bash file.sh
CentOS 6 32位
CentOS 6 32-bit
出了什么问题?第一次使用BASH时,需要它在某个东西上进行简单的无限循环.
What is the issue? First time EVER using BASH, need it for a simple infinite loop on something.
推荐答案
运行cat -v file.sh
.
您的文件中很可能有回车符或不间断空格. cat -v
分别将它们显示为^M
和M-BM-
或M-
.它将类似地显示您可能在文件中遇到的任何其他奇怪字符.
You most likely have a carriage return or no-break space in your file. cat -v
will show them as ^M
and M-BM-
or M-
respectively. It will similarly show any other strange characters you might have gotten into your file.
使用
tr -d '\r' < file.sh > fixedfile.sh
这篇关于意外令牌“完成"附近的BASH语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文