家庭宽带做私人网站,网站建设哪方面最重要的呢,苏州出名的网站公司,网站建设需要知识shell(2)
简答题
1、编写一个shell脚本#xff0c;从键盘读入一个成绩#xff0c;并按优秀、良好、中等、及格、不及格输出成绩。
我的答案#xff1a;
#/bin/bash
read -p 请输入学生成绩(0-100)#xff1a; score
if [ $sum -gt 100 ] ;thenecho 输…shell(2)
简答题
1、编写一个shell脚本从键盘读入一个成绩并按优秀、良好、中等、及格、不及格输出成绩。
我的答案
#/bin/bash
read -p 请输入学生成绩(0-100) score
if [ $sum -gt 100 ] ;thenecho 输入有误成绩大于100
elif [ $sum -ge 90 ] ;thenecho 优
elif [ $sum -ge 80 ] ;thenecho 良
elif [ $sum -ge 70 ] ;thenecho 中
elif [ $sum -ge 60 ] ;thenecho 及格
elif [ $sum -ge 0 ] ;thenecho 不及格
elif [ $sum -lt 0 ] ;thenecho 输入有误成绩小于0
fi参考答案 :
#!/bin/bash
next:
read -p please input a score: score 2分
if [ $score lt 0 -o $score gt 100 ] 4分
thenecho illegal score,please input againgoto next
fi
if [ $score ge 90 ] 6分
thenecho A
elif [ $score -ge 80 ] 7分
thenecho B
elif [ $score -ge 70 ] 8分
thenecho C
elif [ $score -ge 60 ] 9分
thenecho D
Else 10分echo E
fi2、请用shell程序写出求1~100所有素数的和。
我的答案
#!/bin/bash
for((i1;i100;i))
doif((i2))thenif((i2))thenlet sumifielseflag0for((j2;ji/2;j))doif((i%j0))thenflag1breakfidoneif((flag0))thenlet sumififi
done
echo all prime(1~100) sum is $sum参考答案 :
#!/bin/bash
sum0
for((i1;i100;i))
doflag0for((j2;ji/2;j))doif((i%j0))thenflag1breakfidoneif((flag0))thenlet sumifi
done
echo $sum3、有一个IP地址文件ip.txt内容如下
10.22.110.1
10.22.110.10
10.22.110.30
10.22.110.20
10.22.110.40
10.22.110.50
10.22.110.60
请写一个shell程序统计出有多少台主机可ping通多少台主机不可Ping通。
我的答案
#!/bin/bash
n10
n20
while read line
doping $line -c 3if [ $? -eq 0 ] then let n1eliflet n2fi
doneip.txt
echo there are $n1 machine reachable
echo there are $n2 machine unreachable参考答案 :
#!/bin/bash
n0
m0
for ip in cat ip.txt
doping -c 3 v$ipif [ $? -eq 0 ]thenlet nelselet mfi
done
echo reachable :$n, unreachable: $m