If to determine the size of two values -- multi-branch if statement to strictly judge the parameters

Source: Internet
Author: User
If to determine the size of two values -- multi-branch if statement to strictly judge the parameters

#! /Bin/bash

Print_usage (){

Printf "the number of parameters you entered is incorrect or incorrect. Run the following syntax: \ n"

Echo-e "$0 digit 1 digit 2"

Exit1

}

If [$ #-ne 2]

Then

Print_usage

Exit1

Fi

[-N "'echo $1 | SED's/[0-9] // g''"-a-n "'echo $2 | SED's/[0 -9] // g'' "] & Echo" Both parameters must be numbers "& Exit 1

 

[-N "'echo $1 | SED's/[0-9] // g''"] & Echo "the first parameter must be a number" & Exit 1

[-N "'echo $2 | SED's/[0-9] // g''"] & Echo "the second parameter must be a number" & Exit 1

If [$1-GT $2]

Then

Echo "$1> $2"

Elif [$1-lt $2]

Then

Echo "$1 <$2"

Else

Echo "$1 = $2"

Fi

1. Single judgment syntax

[-N "'echo $1 | SED's/[0-9] // g''"] & Echo "the first parameter must be a number" & Exit 1

[-N "'echo $2 | SED's/[0-9] // g''"] & Echo "the second parameter must be a number" & Exit 1

2. Normal variable judgment

[-N "'echo $2 | SED's/[0-9] // g''"] & {

Echo "the second parameter must be a number"

Exit1

}


If to determine the size of two values -- multi-branch if statement to strictly judge the parameters

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.