- 1、编写⼀段shell程序实现以下功能:
根据键盘输⼊的学⽣成绩,显示相应的成绩等级, 其中
60分以下为"Failed!“,
60~69分为"Passed!”,
70~79分为"Medium!“,
80~89分为"Good!”,
90~100为"Excellent!“。
如果输⼊超过100的分数,则显示"error score”;
实验eg,
代码。。。 - 编写一个shell程序可以完成以下执行过程。
[root@localhost ~]# ./main.sh
Input a list of number:
1 2 3 4 5 6
the result is 21
Input a list of number:
1 1 1
the result is 3
Input a list of number:
q
[root@localhost ~]#
#! /bin/bash
while true
do
echo "input a list of number:"
read num1
result=0
case $num1 in
q|Q)
exit
;;
#这里可以直接if判断就好了,
esac
for val in $num1
do
result=`expr $result + $val`
done
echo "the result is $result"
done
实验部分
实验5:
eg3:
# ! /bin/bash
func(){
echo "input a directory:"
}
func
while read dir
do
if [ $dir = "q" ];then
exit
elif [ -e $dir -a -d $dir ];then
for file in `ls $dir`
do
if [ ! -e "$dir$file" ];then
dd="$dir/$file"
else
dd="$dir$file"
fi
type=`ls -ld $dd | cut -c1`
echo "${dd}_${type}"
done
else
echo "$dir is not a directory"
fi
echo -e
func
done
实验6
#! /bin/bash
echo "please, input a number:"
read num
for((i=$num; i>=1; i--))
do
for((j=$i; j>=1; j--));do
echo -n "$j "
done
echo
done