#!/bin/sh
比较2个数的大小
#by zkg 2019-07-31
read -p "please input tow num:" num1 num2
a=$num1
b=$num2
#必须是2个数
[ -z "$a" -o -z "$b" ]&&{
echo "USAGE:NUM1 NUM2"
exit 1
}
#必须是2个参数是整数
[ "echo "$a"|sed -r 's/[^0-9]//g'
" = "$a" ]||{
echo "must be int"
exit 2
}
[ "echo "$b"|sed -r 's/[^0-9]//g'
" = "$b" ]||{
echo "must be int"
exit 2
}
#比较两个数的大小
[ "$a" -eq "$b" ]&&{
echo "$a=$b"
exit 0
}
[ "$a" -gt "$b" ]&&{
echo "$a>$b"
exit 0
}
[ "$a" -lt "$b" ]&&{
echo "$a<$b"
exit 0
}