该程序旨在创建一个随机数,并检查该数字是否小于,大于或等于用户在计数小于3时输入的数字。
#!/bin/sh
ranNum=$(($RANDOM % (2 - 1)))
ranNum=$((1 + $ranNum))
c=1
echo "The entity with the greatest number wins"
while [ $c -lt 3 ]
do
echo "Enter a number"
read usrIn
if ["$usrIn" -gt "$ranNum"]
then
echo "You won"
((c++))
if ["$usrIn" -lt "$ranNum"]
then
echo "You lost"
((c++))
else
echo "Its a tie"
((c++))
break
fi
done
当我在外壳中运行代码时,我得到2个错误:
第24行:意外令牌done'
line 24:
完成附近的语法错误
我不确定我的代码的语法有什么问题,或者从这里去哪里。
答案 0 :(得分:3)
第二个“ if”语句应为“ elif”