[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?