从书上抄的个shell脚本 sleep.sh
如下:
echo -n count:
tput sc
count=0;
while true;
do
if [ $count -lt 40 ]
then let count++;
sleep 1;
tput rc
tput ed
echo -n $count;
else exit 0;
fi
done
~
执行后报错:
count:./sleep.sh: line 8: syntax error near unexpected token `then'
./sleep.sh: line 8: ` then let count++;'
刚开始学习对shell脚本语法不清楚,原因如下:
1.if后要有空格
2.[] 中括号的开头和结尾要有空格!
3. [ $count -lt 40 ]中括号中的$1和-eq和"root"之间不需要空格!
修改以后如下(可正常执行):
echo -n count:
tput sc
count=0;
while true;
do
if [ $count-lt40 ]
then let count++;
sleep 1;
tput rc
tput ed
echo -n $count;
else exit 0;
fi
done
本文介绍了一个简单的Shell脚本,该脚本用于演示如何通过正确的语法实现计数器功能,并在屏幕上更新显示。文章首先展示了包含语法错误的原始脚本,随后指出了问题所在并给出了修正后的版本。
1万+

被折叠的 条评论
为什么被折叠?



