Original: shell two integers comparison idea version, shell integer

Source: Internet
Author: User

Original: shell two integers comparison idea version, shell integer

The idea is to learn code creation. I like the logic rigor of the first few lines.

#! /Bin/bash
# Determine the size of two integers
Read-p "enter two integers a B:" a B
# Or use a = $1
[-Z "$ a"] | [-z "$ B"] & {
Echo "the number you entered is zero"
Exit 1
}
# Whether the input value is 0
Expr $ a + 10 &>/dev/null
RETUAL1 = $?
Expr $ B + 10 &>/dev/null
Retual = $?
# Judge whether the input value is an integer
Test $ RETUAL1-eq 0-a $ retual-eq 0 | {
Echo "the variable is not an integer and 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
}

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.