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 页