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