#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
}
第11题:开发shell脚本分别实现以脚本传参以及read读入的方式比较2个整数大小
原文:https://blog.51cto.com/1009516/2428710