Using the shell to complete the size comparison of two numbers

Source: Internet
Author: User

Brief description:

Prompts the user to enter two numbers;

Determine whether the input content is a number;

Numbers do calculations and feedback results;

When the calculation is complete, ask the customer whether to continue using;

Provides a way for users to exit at any time.

[email protected] scripts]# cat jisuan2.sh

#!/bin/bash


# # #thank_oldboy

# # #2016/3/6

# # #i wish the best.

. /etc/init.d/functions


# # Read number.

function Read_number() {

Read-p "Please enter the Number1:" Num1

Read-p "Please enter the number2:" num2

Panduan_number

}


# # # Judge $number 1 $number 2 both is number.

function Panduan_number() {

Expr $num 1 + $num 2 &>/dev/null

[$?-ne 0] && {

[[$num 1 = = Exit | | $num 2 = exit]] && {

echo "You had choice Leave,bye."

Exit 0

} || {

echo "Usage:you must enter the numbers, or enter exit to leave."

Read_number

}

} || Judge_number

}


# # # Judge continue or exit.

function continue_or_exit() {

Read-p "Please enter the go to continue or enter off to leave:" Str

Case ' $str ' in

Go

Read_number

;;

Out

echo "Hope to see you again,bye."

Exit 0


;;

*)

echo "Usage:enter Go or Out:"

Continue_or_exit

;;

Esac

}


# # # expr $number 1 $number 2.

function Judge_number() {

[$num 1-eq $num 2] && {

echo "$num 1 equal $num 2."

Continue_or_exit

}

[$num 1-gt $num 2] && {

echo "$num 1 greater than $num 2."

Continue_or_exit

}

[$num 1-lt $num 2] && {

echo "$num 1 lower than $num 2."

Continue_or_exit

}

}



# # # The Gate of the script.

function main() {

Read_number

}

Main


Using the shell to complete the size comparison of two numbers

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.