Use the IF statement to determine the size of the two numbers in two ways.
The first type:
The number of #!/bin/basha=$1b=$2# parameters is not equal to 2 of the case [ $# -ne 2 ]&&{ echo "Usage:$0 num1 num2" exit &NBSP;1} #计算返回值expr $a + 0 &>/dev/nullRETVAL1=$?expr $b + 0 &>/dev/nullretval2=$? #返回值的结果必须都为0 $? The return value of the previous command 0 indicates a successful test $RETVAL 1 -eq 0 -a $RETVAL 2 -eq 0| | { echo "please enter input two " num " again. " &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;EXIT&NBSP;2} #比较if [ $a -eq $b ];then echo "$a = $b" elif [ $a -gt $b ];then echo "$a > $b" elif [ $a -lt $b ];then echo "$a < $b" else EXITFI Note: The script may have characters on this page will automatically become Chinese characters, if posted out of the operation may be error, only slowly hit.
The second Kind
#!/bin/bashread -t 5 -p "Please enter input two num:" a b# The judge is whether the string length is equal to zero, and if equal to zero is true [ -z "$a" ] | | [ -z "$b" ]&&{ echo "please enter input two num agagin. " &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;EXIT&NBSP;1} #判断返回值的结果是否为trunexpr $a + 0 &>/dev/nullRETVAL1=$?expr $b + 0 &>/dev/nullretval2=$? #判断返回值的结果是否都是truntest $RETVAL 1 -eq 0 -a $RETVAL 2 -eq 0| | { echo "please enter input two " num " again. " &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;EXIT&NBSP;2} #判断大小if [ $a -eq $b ]; then echo "$a = $b" elif [ $a -gt $b ];then echo "$a > $b" elif [ $a -lt $b ];then echo "$a < $b" else exit 3fiexit Note: The script may have characters on this page will automatically become Chinese characters, if posted out of the operation may be error, only slowly hit.
Summarize:
Learning scripts can only be practiced more slowly to form a script thinking, or will never write their own script.
This article is from the "sub-non-fish" blog, please be sure to keep this source http://5323197.blog.51cto.com/5313197/1788053
Digital comparison size Script