linux的shell脚本实验报告.doc

linux的shell脚本实验报告.doc

ID:57395251

大小:30.50 KB

页数:7页

时间:2020-08-15

linux的shell脚本实验报告.doc_第1页
linux的shell脚本实验报告.doc_第2页
linux的shell脚本实验报告.doc_第3页
linux的shell脚本实验报告.doc_第4页
linux的shell脚本实验报告.doc_第5页
资源描述:

《linux的shell脚本实验报告.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、第二次实验内容一、实验名称:Linux下shell编程二、实验类型:设计三、实验目的:1.熟悉Linux的shell几种变量使用2.熟练掌握Linux的shell编程几种结构3.熟练掌握Linux下shell脚本的编写四、实验准备参考教材,课件第7章内容及笔记。要求实验内容全部写到实验报告上(B5纸)。五、实验内容1.练习使用shell四种变量,参考课件例题。用户自定义变量,环境变量,位置变量,特殊变量这四种变量类型的使用,书中有例题。2.调试课件所有shell脚本的例题。3.编写如下脚本:l编写脚本if1,测试其功能。echo-n"word1:"readword1echo-

2、n"word2:"readword2iftest"$word1"="$word2"thenecho"Match"fiecho"Endofprogram."l编写脚本chkargs,测试其功能iftest$#-eq0thenecho"Youmustsupplyatleastoneargument."exit1fiecho"Programrunning."l编写脚本if2,测试其功能iftest$#-eq0thenecho"Youmustsupplyatleastoneargument."exit1fiiftest-f"$1"thenecho"$1isaregularfilein

3、theworkingdirectory"elseecho"$1isNOTaregularfileintheworkingdirectory"fil编写脚本if3,测试其功能echo-n"word1:"readword1echo-n"word2:"readword2echo-n"word3:"readword3if["$word1"="$word2"-a"$word2"="$word3"]thenecho"Match:words1,2,&3"elif["$word1"="$word2"]thenecho"Match:words1&2"elif["$word1"="$word3"

4、]thenecho"Match:words1&3"elif["$word2"="$word3"]thenecho"Match:words2&3"elseecho"Nomatch"fil编写smartzip脚本,测试其功能#!/bin/bashftype=`file"$1"`case"$ftype"in"$1:Ziparchive"*)unzip"$1";;"$1:gzipcompressed"*)gunzip"$1";;"$1:bzip2compressed"*)bunzip2"$1";;*)echo"File$1cannotbeuncompressedwithsmartzi

5、p";;esacl编写脚本dirfiles,测试其功能。foriin*doif[-d"$i"]thenecho"$i"fidonel编写脚本until1,测试其功能。用while改写之。secretname=jennyname=nonameecho"Trytoguessthesecretname!"echountil["$name"="$secretname"]//while改写位while[“$name”!=“$secretname”],其他地方不变doecho-n"Yourguess:"readnamedoneecho"Verygood."l编写脚本brk,测试其功能。f

6、orindexin12345678910doif[$index-le3];thenecho"continue"continuefi#echo$index#if[$index-ge8];thenecho"break"breakfidonel编写脚本command_menu,测试其功能。echo-e"COMMANDMENU"echo"a.Currentdateandtime"echo"b.Userscurrentlyloggedin"echo"c.Nameoftheworkingdirectory"echo-e"d.Contentsoftheworkingdirector

7、y"echo-n"Entera,b,c,ord:"readanswerechocase"$answer"ina)date;;b)who;;c)pwd;;d)ls;;*)echo"Thereisnoselection:$answer";;esacl编写脚本demo_shift,测试其功能。echo"arg1=$1arg2=$2arg3=$3"shiftecho"arg1=$1arg2=$2arg3=$3"shiftecho"arg1=$1arg2=$2arg3=$3"shiftecho"arg1=$1

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。