预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共19页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

一、Shell编程要求:写出两个Shell程序,每个程序不少于十五行;说明程序主要功能;每行给出注释。 #MajorFunction:simplecalculatorfor+-#/ # #Time:SundayMay5,2013 # #copyright: #!/bin/bash #!/bin/sh main() { echo"calculatorV1.0" #选择操作方式helporcalulateorexit while[1] do readselect if["$select"="help"] then echo"1calculator" echo"0exit" elif["$select"="1"] then cal; elif["$select"="0"] then break; fi done } cal() { readstr #针对读入的字串,提取操作数及操作符 num1=`echo$str|cut-d''-f1` num2=`echo$str|cut-d''-f3` sign=`echo$str|cut-d''-f2` #根据sign选择对应操作+-#/ case$signin +) sum=`expr$num1+$num2`; echo"$num1$sign$num2=$sum";; -) sum=`expr$num1-$num2`; echo"$num1$sign$num2=$sum";; \#) sum=`expr$num1\*$num2`; echo"$num1*$num2=$sum";; /) sum=`expr$num1/$num2`; echo"$num1$sign$num2=$sum";; esac } main #!/bin/bash #数字游戏 random() { FLOOR=0 RANGE=10 num=0 while[$num-le$FLOOR] do num=$RANDOM #通过使随机数成为指定范围的随机数 let"num%=$RANGE" done #echo"Randomnumberbetween$FLOORand$RANGE---$number" return } random ######################## D1=$num random D2=$num while[$D2==$D1] dorandom D2=$num done random D3=$num while[$D3==$D2]||[$D3==$D1] dorandom D3=$num done random D4=$num while[$D4==$D3]||[$D4==$D2]||[$D4==$D1] dorandom D4=$num done #echo$D1$D2$D3$D4#########Thisisfortest input_num() { #输入四个数据并判断比较对错情况返回?A?B echo echo"Pleaseinputfourdifferentnumbersbetween1~9(Justlikethis\"5214\")" readS1S2S3S4 } zero() { while[$S1==0]||[$S2==0]||[$S3==0]||[$S4==0] doecho"zeroisnotallowd" input_num done } input_num zero while[$S1==$S2]||[$S1==$S3]||[$S1==$S4]||[$S2==$S3]||[$S2==$S4]||[$S3==$S4] doecho"wronginput" input_num done echo$S1$S2$S3$S4 declareA declareB #比较函数 compare() { A=0 B=0 if[$S1==$D1] thenletA=$A+1 elif[$S1==$D2]||[$S1==$D3]||[$S1==$D4] thenletB=$B+1 fi if[$S2==$D2] thenletA=$A+1 elif[$S2==$D1]||[$S2==$D3]||[$S2==$D4] thenletB=$B+1 fi if[$S3==$D3] thenletA=$A+1 elif[$S3==$D1]||[$S3==$D2]||[$S3==$D4] thenletB=$B+1 fi if[$S4==$D4] thenletA=$A+1 elif[$S4==$D1]||[$S4=