LINUXShell编程实验报告.docx
《LINUXShell编程实验报告.docx》由会员分享,可在线阅读,更多相关《LINUXShell编程实验报告.docx(10页珍藏版)》请在冰豆网上搜索。
LINUXShell编程实验报告
LINUX-Shell编程实验报告
《LINUX管理与应用》课程实验报告
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
实验内容和目的
实验目的:
理解Shell程序的设计方法;熟悉Shell程序编辑、运行、调试方法与过程。
实验内容:
(1)Shell简单编程
用户名回显程序;if-then、if-then-else语句使用;for语句、while语句使用
(2)较复杂的考勤模拟shell程序设计
实验环境
微机、WINDOWSXP、QUICKLINUX、VMWARE虚拟机软件
实验重点及难点
实验重点:
SHELL编辑、运行过程;SHELL变量的使用,分支语句的设计,循环语句的设计
实验难点:
SHELL语句的使用方法
实验过程(实验过程、实验结果及实验分析)
一、实验过程
1.编写一个简单的回显用户名的shell程序
2.使用if-then语句创建简单的shell程序
3.使用if-then-else语句创建一个根据输入的分数判断是否及格的shell程序
4.使用for语句创建简单的shell程序
5.使用while语句创建一个计算1-5的平方的shell程序
6.用shell设计一个模拟考勤程序
二、实验结果
1.编写一个简单的回显用户名的shell程序
#vidat
#!
/bin/bash
#filename:
dat
echo"Mr.$USER,Todayis:
"
echo`date`
echoWishyoualuckyday!
#chmod+xdat
#./dat
2.使用if-then语句创建简单的shell程序
echo$ab
done
#chmod+xmm
#./mm
5.使用while语句创建一个计算1-5的平方的shell程序
#vizx
#!
/bin/bash
#filename:
zx
int=1
while[$int-le5]
do
sq=`expr$int\*$int`
echo$sq
int=`expr$int+1`
done
echo"Jobcompleted"
#chmod+xzx
#./zx
6.用shell设计一个模拟考勤程序,实现如下功能选择界面:
1:
上班签到2:
下班签出3:
缺勤信息查阅
#vitestshell
#!
/bin/bash
#filename:
shelltest
exsig=0
whiletrue;do
echo""
echo"----欢迎使用本系统----"
echo"1.上班签到"
echo"2.下班签出"
echo"3.考勤信息查询"
echo"4.退出系统"
echo"----------------------"
echo""
echo"请输入你的选项:
"
readchoice
case$choicein
1)echo"请输入你的名字:
"
readname
echo"请输入你的密码:
"
readpassword
iftest-r/home/user/userinfo.dat
then
whilereadfnamefpassword
do
echo"$fname"
echo"$fpassword"
iftest"$fname"="$name"
then
break
fi
done
else
echoSystemError:
userinfo.datdoesnotexist!
fi
iftest"$fname"!
="$name"
then
echo"不存在该用户!
"
eliftest"$fpassword"!
="$password"
then
echo"密码不正确!
"
else
hour=`date+%H`
iftest"$hour"-gt8
then
echo"你迟到了!
"
echo"$name上班迟到---日期:
`date`">>/home/user/check.dat
else
echo"早上好,$name!
"
fi
fi
;;
2)echo"请输入你的名字:
"
readname
echo"请输入你的密码:
"
readpassword
iftest-r/home/user/userinfo.dat
then
whilereadfnamefpassword
do
iftest"$fname"="$name"
then
break
fi
done
else
echoSystemError:
userinfo.datdoesnotexist!
fi
iftest"$fname"!
="$name"
then
echo"不存在该用户!
"
eliftest"$fpassword"!
="$password"
then
echo"密码不正确!
"
else
hour=`date+%H`
iftest"$hour"-lt18
then
echo"你早退了!
"
echo"$name下班早退----日期:
`date`">>/home/user/check.dat
else
echo"再见,$name!
"
fi
fi
;;
3)echo"请输入你的名字:
"
readname
echo"请输入你的密码:
"
readpassword
iftest-r/home/user/userinfo.dat
then
whilereadfnamefpassword
do
iftest"$fname"="$name"
then
break
fi
done
else
echoSystemError:
userinfo.datdoesnotexist!
fi
iftest"$fname"!
="$name"
then
echo"不存在该用户!
"
eliftest"$fpassword"!
="$password"
then
echo"密码不正确!
"
else
echo"你的记录:
"
echo"---------"
cat-b/home/user/check.dat|grep$name
echo"---------"
fi
;;
4)echo"欢迎你的使用,再见!
"
exsig=1
;;
*)echo"请输入合法的选项!
"
;;
esac
iftest"$exsig"="1"
then
break
fi
done
七.试验运行结果:
#chmod+xtestshell
#./testshell
三、实验分析
通过这次实验,我懂得了定义SHELL程序设计中的变量,掌握了SHELL程序中LINUX基本命令的使用,理解了Shell程序的设计方法,并且熟悉了Shell程序编辑、运行、调试方法与过程。
这为我日后继续深入学习Linux课程打下基础。