《LINUX管理与应用》课程实验报告≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡实验内容和目的实验目的:理解Shell程序的设计方法;熟悉Shell程序编辑、运营、调试方法与过程实验内容:(1)Shell 简朴编程用户名回显程序;if-then、if-then-else语句使用;for语句、while语句使用(2)较复杂的考勤模拟shell程序设计实验环境微机、WINDOWS XP、QUICK LINUX、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程序#vi dat#!/bin/bash#filename:datecho "Mr.$USER,Today is:"echo `date`echo Wish you a lucky day!#chmod +x dat#./dat2. 使用if-then语句创建简朴的shell程序#vi bbbb#!/bin/bash#filename:bbbbecho -n "Do you want to continue: Y or N"read ANSWERif [ $ANSWER = N -o $ANSWER = n ]then echo "your answer is quit! "fi#chmod +x bbbb#./bbbb3. 使用if-then-else语句创建一个根据输入的分数判断是否及格的shell程序#vi ak#!/bin/bash#filename:akecho -n "please input a score:"read SCOREecho "You input Score is $SCORE"if [ $SCORE -ge 60 ];then echo -n "Congratulation!You Pass the examination."elseecho -n "Sorry!You Fail the examination!"fiecho -n "press any key to continue!"read $GOOUT#chmod +x ak#./ak4. 使用for语句创建简朴的shell程序#vi mm#!/bin/bash#filename:mmfor ab in 1 2 3 4do echo $abdone#chmod +x mm#./mm5. 使用while语句创建一个计算1-5的平方的shell程序#vi zx#!/bin/bash#filename:zxint=1while [ $int -le 5 ]do sq=`expr $int \* $int`echo $sqint=`expr $int + 1`doneecho "Job completed"#chmod +x zx#./zx6. 用shell设计一个模拟考勤程序,实现如下功能选择界面: 1:上班签到2:下班签出3:缺勤信息查阅# vi testshell#! /bin/bash#filename:shelltestexsig=0while true; do echo "" echo "----欢迎使用本系统----" echo " 1. 上班签到" echo " 2. 下班签出" echo " 3. 考勤信息查询" echo " 4. 退出系统" echo "----------------------" echo "" echo "请输入你的选项:" read choice case $choice in 1)echo "请输入你的名字:" read name echo "请输入你的密码:" read password if test -r /home/user/userinfo.dat then while read fname fpassword do echo "$fname" echo "$fpassword" if test "$fname" = "$name" then break fi done < /home/user/userinfo.dat else echo System Error:userinfo.dat does not exist! fi if test "$fname" != "$name" then echo "不存在该用户!" elif test "$fpassword" != "$password" then echo "密码不对的!" else hour=`date +%H` if test "$hour" -gt 8 then echo "你迟到了!" echo "$name 上班迟到---日期:`date`" >>/home/user/check.dat else echo "早上好,$name!" fi fi ;; 2)echo "请输入你的名字:" read name echo "请输入你的密码:" read password if test -r /home/user/userinfo.dat then while read fname fpassword do if test "$fname" = "$name" then break fi done < /home/user/userinfo.dat else echo System Error:userinfo.dat does not exist! fi if test "$fname" != "$name" then echo " 不存在该用户!" elif test "$fpassword" != "$password" then echo "密码不对的!" else hour=`date +%H` if test "$hour" -lt 18 then echo "你早退了!" echo "$name 下班早退----日期:`date`">> /home/user/check.dat else echo "再见,$name!" fi fi ;; 3)echo "请输入你的名字:" read name echo "请输入你的密码:" read password if test -r /home/user/userinfo.dat then while read fname fpassword do if test "$fname" = "$name" then break fi done < /home/user/userinfo.dat else echo System Error:userinfo.dat does not exist! fi if test "$fname" != "$name" then echo "不存在该用户!" elif test "$fpassword" != "$password" then echo "密码不对的!" else echo "你的记录:" echo "---------" cat -b /home/user/check.dat|grep $name echo "---------" fi ;; 4)echo "欢迎你的使用,再见!" exsig=1 ;; *)echo "请输入合法的选项!" ;; esac if test "$exsig" = "1" then break fidone七.实验运营结果:#chmod +x testshell#./testshell三、 实验分析通过这次实验,我懂得了定义SHELL程序设计中的变量,掌握了SHELL程序中LINUX基本命令的使用,理解了Shell程序的设计方法,并且熟悉了Shell程序编辑、运营、调试方法与过程。
这为我日后继续进一步学习Linux课程打下基础。