Original: Shell Two-integer comparison thought version

Source: Internet
Author: User

The idea is to learn the code creation is their own very like the first few lines of logic rigorous

#!/bin/bash
#判断两个整数的大小
Read-p "Please enter two integers a B:" A B
#或者使用a =$1
[-Z "$a"]| | [-Z "$b"]&&{
echo "The number you entered is zero"
Exit 1
}
#输入的值是否为0
Expr $a + &>/dev/null
Retual1=$?
Expr $b + &>/dev/null
Retual2=$?
#判断输入的值是不是整数
Test $RETUAL 1-eq 0-a $RETUAL 2-eq 0 | | {
echo "Variable not an integer does not meet the requirements"
Exit
}
[$a-lt $b] &&{
echo "$a < $b"
Exit 3
}
[$a-gt $b] &&{
echo "$a > $b"
Exit 4
}
[$a-eq $b] &&{
echo "$a = $b"
Exit 5
}

Original: Shell Two-integer comparison thought version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.