1

该程序旨在创建一个随机数并检查它是否小于、大于或等于用户在计数小于 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

当我在 shell 中运行代码时,返回 2 个错误:

第 24 行:意外标记done' line 24:完成附近的语法错误

我不确定我的代码语法有什么问题或从这里去哪里。

4

1 回答 1

3

第二个“if”语句应该是“elif”

于 2019-05-04T19:08:52.867 回答