linux简易学生成绩计算实验,Linux实验1报告.doc

Linux实验1报告.doc

仲恺农业工程学院实验报告纸

(院、系) 专业 班 Linux系统编程 课

学号 姓名 实验日期 教师评定

实验1 Shell 程序设计

一、实验目的

重点掌握shell编程的规则。

二、实验环境

硬件:每个学生需配备计算机一台,操作系统:linux。

三、实验题目和实验内容

实验题目: Shell程序设计

实验内容:

1、设计如下一个菜单驱动程序。

Use one of the following options:

P:To display current directory

S:To display the name of running file

D:To display today’s date and present time

L:To see the listing of files in your present working directory

W:To see who is logged in

Q:To quit this program

Enter your option and hit:

菜单程序根据用户输入的选择给出相应信息。要求对用户的输入忽略大小写,对于无效的输入给出相应的提示。

2、根据从键盘输入的学生成绩,显示相应的成绩等级,其中60分以下为“Failed!”,60~70分为“Passed!”,70~80分为“Medium!”,80~90分为“Good!”,90~100分为“Excellent!”。如果输入超过100分或低于0分,则显示错误分数提示。

3、打印1-99之间的奇数到文件。

四、实验数据和实验结果(程序运行结果的截图)

1、

2、

3、

五、附录(程序代码)

1、代码如下:

#!/bin/bash

#menu.sh

echo "Use one of the following options:

P:To display current directory

S:To display the name of running file

D:To display today’s date and present time

L:To see the listing of files in your present working directory

W:To see who is logged in

Q:To quit this program

Enter your option and hit:"

read answer

echo

case $answer in

P|p)

pwd;;

S|s)

echo $0;;

D|d)

date;;

L|l)

ls;;

W|w)

who;;

Q|q)

exit;;

*)

echo "there is no selection:$answer";;

esac

2、代码如下:

echo "input student grade:"

read grade

if [ $grade -lt 0 -o $grade -gt 100 ]

then

echo "wrong"

elif [ $grade -lt 60 ]

then

echo "failed"

elif [ $grade -lt 70 ]

then

echo "passed"

elif [ $grade -lt 80 ]

then

echo "medium"

elif [ $grade -lt 90 ]

then

echo "good"

elif [ $grade -le 100 ]

then

echo "excellent"

fi

3、打印1-99之间的奇数到文件。

i=1

until [ $i -gt 100 ]

do

if [ `expr $i % 2` -eq 1 ]

then

echo $i >> test

fi

i=`expr $i + 1`

done

心得

通过这次实验 ,我懂得了shell程序的一些设计。

第 1 页 共 6 页

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值