实验四--LINUX-Shell编程_第1页
实验四--LINUX-Shell编程_第2页
实验四--LINUX-Shell编程_第3页
实验四--LINUX-Shell编程_第4页
实验四--LINUX-Shell编程_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精品文档实验四LINUX-Shell编程(4学时)一.实验名称:Shell简单编程实验和较复杂的考勤模拟shell程序设计二.实验目的:理解Shell程序的设计方法;熟悉 Shell程序的编辑、运行、调试方法与过程。三.实验内容:考勤模拟Shell程序设计用shell设计一个模拟考勤程序,实现如下功能选择界面:1 :上班签到2 :下班签出3 :缺勤信息查阅考勤程序运行后,提示用户输入上述功能选择,并验证用户输入的用户名和密码;用户信息保存在 userinfo.dat 中。如果是上班签到,记录签到信息,如果签到时间大于上午8时,则提示用户迟到,并记录该迟到信息到 check.dat中。如果是下班

2、签出,记录签出信息,如果签出时间小于下午6时,则提示用户早退,并记录该早退信息到 check.dat 。如果用户选择确信信息查询,则将check.dat中对应的用户迟到早退的信息查询出来并 显示。用户选择功能执行完,Shell程序继续回到功能选择界面等待下一个用户进行操作。四.实验要求:1 、掌握Shell程序的编辑、运行、调试方法2 、完成实验内容要求的功能五.简单SHELL实验:请在vi中逐一编辑并执行以下 6个shell脚本程序1 .编写一个简单的回显用户名的shell程序。#vi dat#!/bin/bash#filename:datecho Mr.$USER,Today is:ech

3、o dateecho Wish you a lucky day!#chmod +x dat#./datl_H8mingloalho5t practice| S Isak dat mn sum xxniingMocalhost practice1 $ ./datMr. Ming Todat is;201 4年 06月 LI 日 星期一 22:11: 31 C5TWish you a lucky day!ruing向localhost practice| 5 |2 .使用if-then-else语句创建一个根据输入的分数判断是否及格的shell程序。#vi ak#!/bin/bash#filena

4、me:akecho -n please input a score:read SCOREecho You input Score is $SCOREif $SCORE -ge 60 ;thenecho -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#./ak| minglocalho&t practice $ Jak please input a s

5、core;50You input Score is 60Congratulation! You pass the examination, press any key to continue minglocalhost practice $ ./ak please input a score;59You input Score is 59Sorry! You Tail the examination! press any key to continuel3 .使用for语句创建简单的shell程序。#vi mm#!/bin/bash#filename:mm for ab in 1 2 3 4d

6、oecho $abdone#chmod +x mm#./mmminglocalhost practical $ l& ak dat mm sum xxmingMocalhost practice $ , /mn234minglocalhost practice 4.使用while语句创建一个计算 1-5的平方的shell程序。#vi zx#!/bin/bash#filename:zxint=1while $int -le 5 dosq=expr $int * $intecho $sqint= expr $int + 1doneecho Job completed#chmod +x zx#./z

7、xminglocalhost practice $ l邑ak dat mm sum xxmingMocalhost practice $ , / xx14 g 16 25Job completed ningSlocalhost practice $ |5.使用while语句创建一个根据输入的数值求累加和(1+2+3+4+n)的shell程序。#vi sum#!/bin/bash#filename:sumecho -n Please Input Number:read NUMnumber=0sum=0while $number -le $NUM doecho numberecho $number

8、number= expr $number + 1echo sumecho $sumsum= expr $sum + $number doneecho#chmod +x sum#./sumrringlocalhost practice| S ./surn Please input number; 4 number0sum0 number15101 number2 sum3 number3 sum6number4 sum10iringrtocalhast practice $ |六.较复杂SHELL实验(使用VI编辑下面代码)# vi testshell#! /bin/bash#filename:

9、shelltest exsig=0while true; doecho echo -欢迎使用本系统 -echo 1.上班签到”echo 2.下班签出”echo 3.考勤信息查询echo 4.退出系统echo echo echo 请输入你的选项:read choicecase $choice in1)echo 请输入你的名字:read nameecho 请输入你的密码:read passwordif test -r /home/user/userinfo.dat thenwhile read fname fpassword do4欢迎下载精品文档echo $fnameecho $fpasswor

10、dif test $fname = $namethen breakfidone /home/user/check.datelseecho 早上好 ,$name!fifi2)echo 请输入你的名字:read nameecho 请输入你的密码:read passwordif test -r /home/user/userinfo.datthenwhile read fname fpassworddoif test $fname = $namethenbreakfidone /home/user/check.datelseecho 再见 ,$name! fifi;3)echo 请输入你的名字:re

11、ad nameecho 请输入你的密码:read passwordif test -r /home/user/userinfo.datthenwhile read fname fpassworddoif test $fname = $namethenbreakfidone /home/user/userinfo.datelseecho System Error:userinfo.dat does not exist!fiif test $fname != $namethenecho 不存在该用户 !elif test $fpassword != $passwordthenecho 密码不正确

12、!elseecho 你的记录:echo cat -b /home/user/check.dat|grep $nameecho fi;4)echo 欢迎你的使用 , 再见 !exsig=1精品文档*)echo 请输入合法的选项!esacif test $exsig = 1thenbreakfidone七.试验运行结果:#chmod +x testshell#./testshell-欢迎使用本系统-1 .上班签到2 .下班签出3 .考勤信息查询4 .退出系统请输入你的选项:1请输入你的名字:Mirq请输入你的密码:123456Ming12345&你迟到了!欢迎便用本系统1 .上班签到2 .下班签出3 .考勤信息查询4 .退出系统请输入你的选项:2请输入你的名字:Ming请输入你的密码:123456再见,Ming!吹迎使用本系蔬L上班签到2 .下班签出3 .考勤信息查询4 .退出系统请输入你的选项:3请输入你的名字:Ming请输入你的密码:123456你的记录;1 Ming上班迟到-日期:2018年0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论