053-比较输入任意两个数字大小

题目:任意输入两个整数,比较他们的大小

[root@cnsz142728 scripts]# vim pupu.sh
#!/bin/bash
a=$1
b=$2
if [ $# -ne 2 ];then
   echo "USAGE:$0 arg1 arg2"
   exit 2
fi

expr $a + 1 &>/dev/null
start=$?
expr $b + 1 &>/dev/null
start1=$?
if [ $start -ne 0 -a $start1 -ne 0 ]; then
  echo "Please input two again"
  exit 33
fi
if [ $a -eq $b ];then
  echo "$a=$b"
elif [ $a -lt $b ];then
  echo "$a<$b"
elif [ $a -gt $b ];then
  echo "$a>$b"
fi
~
"pupu.sh" [New] 23L, 357C written                             
[root@cnsz142728 scripts]# chmod +x pupu.sh 
[root@cnsz142728 scripts]# ./pupu.sh 
USAGE:./pupu.sh arg1 arg2
[root@cnsz142728 scripts]# ./pupu.sh 3 3
./pupu.sh: line 13: [: -a: integer expression expected
3=3
[root@cnsz142728 scripts]# ./pupu.sh 3 4
./pupu.sh: line 13: [: -a: integer expression expected
3<4
[root@cnsz142728 scripts]# ./pupu.sh 3 1
./pupu.sh: line 13: [: -a: integer expression expected
3>1
[root@cnsz142728 scripts]# ./pupu.sh 2.2 2.2
Please input two again

转载于:https://my.oschina.net/u/3635512/blog/1543614

原文地址:https://www.cnblogs.com/twodog/p/12139314.html