Shell two number of operations, total three variables

Source: Internet
Author: User

#!/bin/bash# Simple script for two number operations A+ -, altogether three parametersEcho$# #对获取的参数以此判断是否包含 [a-za-Z] Something, if included, to exit. Because numbers add up, not numbers, or subtraction. forI_argsinch "[email protected]" Do    Echo$i _argsif[[${i_args} =~ [a-za-z]+]; Then        Echo "contain illegal character"Exit1    fi Done#判断参数个数是3个, add the two digits of the expr parameter if the number is added, and if normal execution returns $?=0, otherwise the execution is not two digits.if[ $# ==3]; Thena=$1C=$2b=$3    Expr$a +2+ $b >/dev/NULL 2>&1The two numbers of the #让expr parameters are added if the numbers are added, and if normal execution returns $?=0, otherwise the execution is not normal two digits errorif[ $? ==0]; Then         Echo "begin calculation"                 Echo$a $c $b |BCElse                 Echo "Please input digit"Exit1    fielif[$#-lt3]; Then#少于三个参数Echo "You are Miss args"Exitelif[$#-GT3]; Then#多余三个参数Echo "You have too many args"Exit1fi

Shell two number of operations, total three variables

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.