Shell script, calculate input given number, judge maximum value, minimum value, sum?

Source: Internet
Author: User

[Email protected] ~]#CatFive.SH #!/bin/bash# Any input 5 numbers, judging the maximum, minimum, sum s=0Read-P"Please input:"Nums=$ (($s +$num)) Max=$nummin=$num forIinch`seq 4` DoRead-P"Please input:"Num S=$ (($s +$num)) if[$num-le $min]; Thenmin=$numfi      if[$num-ge $max]; ThenMax=$numfi DoneEcho sum: $s max: $max min: $min [[email protected]~]# Bash Five.SHPlease input: -Please input: -Please input: +Please input:TenPlease input:0sum: -Max +Min0



[[Email protected]~]#Cat2five.SH #!/bin/bash# Any input 3 numbers, judging the maximum, minimum, sum s=0N=0 forIinch`seq 3` DoRead-P"Please input:"NumExpr${num} +0 1>/dev/NULL 2>&1 if[ $? -eq0]; Then Echo "${num} is a number!" Else Echo "${num} is not a number!"Exitfis=$ (($s +$num)) [$n-eq0] && max= $num && min=$num N=$ (($n +1)) if[$num-le $min]; Thenmin=$numfi if[$num-ge $max]; ThenMax=$numfi DoneEcho sum: $s max: $max min: $min n: $n [[email protected]~]# bash 2five.SHPlease input: + +is a number!Please input: - -is a number!Please input:TenTenis a number!sum: -Max +MinTenN:3[[Email protected]~]#

Shell script, calculate input given number, judge maximum value, minimum value, sum?

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.