Shell Script-Compare two integer sizes

Source: Internet
Author: User

  1. DevelopmentShellscripts are implemented with script arguments , respectively, andReadRead inthe way to compare2an integer size. Use conditional expressions (prohibitif) and remind the user to compare the results in the form of a screen output. Note: Altogether is the development2a script. When you use script to pass parameters andReadthe way you read it requires a hint about whether the variable is a numeric number, and how many arguments are not passed.

Read in mode

#!/bin/bashread-p "Pls input" num: "a b #no1 [-Z" $a "] | | [-Z "$b"] && {echo "Pls input" num again. " Exit 1} #no2expr $a + ten &>/dev/nullretval1=$?expr $b + &>/dev/nullretval2=$?test $RETVAL 1-eq 0-a $RETVA L2-eq 0 | | {echo "pls input" num "again." Exit 2} #num3 [$a-lt $b] &&{echo "$a < $b"} #num4 [$a-eq $b] &&{echo "$a = $b"} #num5 [$a-gt $b] &am P;&{echo "$a > $b"}

Script-Pass Reference

#!/bin/basha=$1b=$2#no1[$#-ne 2] &&{echo "usage:$0 NUM1 NUM2" Exit 1} #no2expr $a + &>/dev/nullretval1= $?expr $b + &>/dev/nullretval2=$?test $RETVAL 1-eq 0-a $RETVAL 2-eq 0 | | {echo "pls input" num "again." Exit 2} #num3 [$a-lt $b] &&{echo "$a < $b"} #num4 [$a-eq $b] &&{echo "$a = $b"} #num5 [$a-gt $b] &am P;&{echo "$a > $b"}


Shell Script-Compare two integer sizes

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.