linux 用shell比较两个整数的大小
1、比较两个整数的大小
#1.判断是不是两个数
[ $# -ne 2 ] && {
echo "Usage:$0 num1 num2"
exit 1
}
#2.判断是否为数字
expr $1 + $2 + 999 &>/dev/null
[ $? -ne 0 ] &&{
echo "请输入两个整数"
exit 2
}
if [ $1 -gt $2 ]
then
echo "$1>$2"
elif [ $1 -lt $2 ]
then
echo "$1<$2"
else
echo "$1=$2"
fi
========================
read -p "please two number: " a b
expr $a + $b + 999 &>/dev/null
if [ $? -ne 0 ]
then
echo "请输入两个整数"
exit 1
else
if [ $a -gt $b ]
then
echo "$a>$b"
elif [ $a -lt $b ]
then
echo "$a<$b"
else
echo "$a=$b"
fi
fi
菜鸟9528号,请求开炮。