我不知道这个脚本有什么问题!!我在这里比较x和y

时间:2019-03-04 17:27:32

标签: linux shell

#!/bin/bash
read x
read y
if [ $x -lt $y ] then                                 
echo "X is less than Y"
fi
if [ $x -gt $y ] then
echo "X is greater than Y"
fi
if [ $x -eq $y ] then
echo "X is equal to Y"
fi

1 个答案:

答案 0 :(得分:1)

您的脚本存在语法错误。将“ then”放在“ if”下方,如下所示:

if [ $x -lt $y ]
then
echo "X is less than Y"
fi

if [ $x -gt $y ]
then
echo "X is greater than Y"
fi

if [ $x -eq $y ]
then
echo "X is equal to Y"
fi

该脚本将起作用:-)。