#!/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