[Email protected] zuoye]#CatQuansges.SH #!/bin/Bash>file[ ! $#-ge3] &&Echo "Please input three number or more number!"&& exit2||Echo$* >file forIinch$* Do Expr$i +1&>/dev/NULL [ $? -ne0] &&Echo "Input is error"&&Exit Donea=`Cat file|Xargs-n1|Sort-n|Head-1' B=`Cat file|Xargs-n1|Sort-n|Tail-1' C=`Cat file|Xargs-n1|Sort-n|WC-l ' d=`Cat file|Xargs-n1|awk '{a+=$1}'END'{print A}'' #[$b-ne0] &&Echo "Max Number:"$b #[$a-ne0] &&Echo "min Number:"$aEcho "average is:"`awk 'begin{printf "%.2f\n",'$d'/'$c'}'' [[email protected] zuoye]# bash quansges.SH 1D1input is error[[email protected] zuoye]# bash quansges.SHD D1input is error[[email protected] zuoye]# bash quansges.SHD d dinput is error[[email protected] zuoye]# bash quansges.SHD1 1input is error[[email protected] zuoye]# bash quansges.SH 1 2 3 4 5 6 7 8 9 0Max Number:9min Number:0average is:4.50[email protected] zuoye]# bash quansges.SH 1 2 3 4 5 6 7 8 9 TenMax Number:Tenmin Number:1average is:5.50[email protected] zuoye]#
A shell script that calculates the maximum and minimum values and averages by passing in parameters.