比较shell脚本中的两个数字

时间:2017-07-02 08:51:44

标签: bash shell

我想比较两个数字,但比较不起作用

read x
read y

if["$x" -lt "$y"]
then
     echo "X is less than Y"
elif["$x" -gt "$y"]
then
     echo "X is greater than Y"
elif["$x" -eq "$y"]
then
    echo "X is equal to Y"
fi

当输入为x = 5y = 2

我得到以下运行时错误:

solution.sh: line 4: if[5 -lt 2]: command not found
solution.sh: line 5: syntax error near unexpected token `then'
solution.sh: line 5: `then 

0 个答案:

没有答案