试验报告六SHELL编程.doc

上传人:scccc 文档编号:12574808 上传时间:2021-12-04 格式:DOC 页数:11 大小:216KB
返回 下载 相关 举报
试验报告六SHELL编程.doc_第1页
第1页 / 共11页
试验报告六SHELL编程.doc_第2页
第2页 / 共11页
试验报告六SHELL编程.doc_第3页
第3页 / 共11页
试验报告六SHELL编程.doc_第4页
第4页 / 共11页
试验报告六SHELL编程.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《试验报告六SHELL编程.doc》由会员分享,可在线阅读,更多相关《试验报告六SHELL编程.doc(11页珍藏版)》请在三一文库上搜索。

1、实验六 SHELL编程实验环境:Linux操作系统实验目的:(1) 掌握vi的三种工作方式,熟悉 vi编辑程序的使用。(2) 学习Shell程序设计方法。掌握编程要领。实验内容:1. 用Vi编写例1。练习内部变量和位置参数的用法。用chmod将文件的权限设置为可执行模式,并在提示符后键入命令行:$./prog1.或 $sh prog1.屏幕显示:Name not provided实验截图:匕tup亡L 4 wi m簞progl.hstupci sh mypcogl.stupcl. -! sh wprogihNdine not provided(stupcl T$ /niwprQgX.h The

2、odore bf»qh; /raprog , h: Mefile or fdi rectory乳喀亡.sh mypragi,h TheodoreYour name is Theodore(stupcl -$ |2. 进一步修改程序progl.h要求显示参数个数、程序名字,并逐个显示参数stupcl *s vi m/progl.h5tupcl -$ ./nyprogl.hYour shell program name 15,/YProq 1 rhstuGlpcl T$ ./myprogl.h H NO KOYour parairieter nunb-er is 3stupcl -S |

3、3修改例1程序。用read命令接受键盘输入。若没有输入显示第一种提示,否则第二种提示。difrlay p ramread chif -2 S<h echo *rat provided echo *rour name is 枇hthenelfi4.用vi编写例2、例3练习字符串比较运 算符、数据比较运算符和文件运算符的用法,观察运行结果。例2:atririgl - "TTlie First one-1string? » "The Second one*string 1 = strings thenecho strina丄 equaL to strLino2we

4、lse<*chc1 noto img?"fli f f 五七 ri ng 1thenecho "atring丄 is not empt/"elser电hui slring3 1( t-npty*fl0T | -n string?t henecho "string has. a Length g re ate than zero* elseecho ring2 has a length equial to zero*(ETugpcl -$ vi co®parestupc 1 *H vi coaipdre.ti(sTupci &h c

5、o«ipare.h stingl not equal o string?stringl is ncl eupty strings lias 启 length grete than zero例3:t -d <ppdir Lhehecho Hcppdir i% directory*pchn " c ppd l r 1 no t h <!i rpc tor/"n(十 filea IthenecM 'filoab rculrels*?'ecrw "tlleanot a regular fils'*r丄t -r filea |t

6、he”echo '"fh住金 read pemj_£iDn$"el s*rcbK " filca du亡、 noL fcdd priiuik'fiw filea rhpnecrw "hds wilLe terni丄s士丄uiif住I 5 H看uhto Hfilconot wrl七乜 pcmiiinc14fiit -x cppdir |thenech-G HcpMdu h<i> eAemte pen rvlic!nMech« Mcippdi r dl&es not have execute perwi

7、s&i of ri运行结果:cppdir 15 not a directory filea is not a regular file filea does net r-ead permissione filefl does net write pernissi口rw cppdir does not have execute pernBsLoii5修改例2程序。使在程序运行中能随机输入字符串,然后进行字符串比较redrjugire-tdst ririgif ( the-n$ rinq. = $st rxi>92 ec ho * s t rir»gi_ c-qu at t

8、o st rir*g2*flecho w st ringl not cqu al to sti ing2*讦 thentstrinl.el teetho stringL is not empty"fiecho " <t nngl is emp ty *if f th en-o 5t ring2 el&eecho ' st ring?agreater- th an z e rorelic * st nr*g2 h<i5 a length equal to I ero4kieukieust r i n g L equal, to st rmqz 亍t

9、 厂i s F)Qt entystr-ing2 h-as q length rater thn 2ero6修改例3程序。使在程序运行中能随机输入文件名,然后进行文件属性判断read filename-d fileandmefilenarti ) thenecho SfllenBHe *q>pdir Is directory'' elseecfw Sfllename *cppdir is not =» directory11 fl:-f filenane thenecho Sfilename fi:f -r filena»e thenecho sfile

10、name d scecho 1 THenaine fi-置 filename then.echo STllenane d sctefwfi -x filename thenechfl $fil亡nameecl"w Sfilenameis a regular file' filea is not a regular file'J-tilea has read p-erniissions'"files dues, not r电aM p«r»LK&ione'*J"filaa has write pcrmisst

11、one""fdlea doe not writ亡 prtni&siQiieJ"tppdir has execute pernissipn"echo ifilename fi匚ppdir do?s nzteie匚utP p?rmission1 stuOpcl f, vi cornpdi«stOci '1$ vi comparedstulpcl -13 wi compareZ.hstupcl *jl ./CGHipare2.hCMparcZ.h(pmparrf.h <ppd1r “ npt a directorycompart

12、. h filea is not a regular f liefiUa doei not read permisie(Offlpare2.h filea does not write permssiorecompare2.h eppdir doe not have execute rmission7. 用vi编写例4、例5、例6、例7掌握控制语句的用法,观察运行结果。例4:IsTuOpcl '15 Text4 hip; missing destination file operand after backup/ Try cp -help' forinfomation./tex

13、t4 h: line 4: : too tvwiy arguffcnt?stu(3pcl *s vi te>t4. h tstuflpcl -is /texT4+icp: missing destination file operand after bd<kup/ Try cp -help* for mare infomaticn.cdev faild.例5:loopco unt = 0 result = 0 while $ loopcou nt It 10 do loopco unt = 'expr $ loopco unt +1' result = '$

14、 result + ( $ loopcou nt * 2) doneecho “ result is $ result ”例6:loopco unt = 0result = 0until $ loopcount - ge 10 doloopco unt = 'expr $ loopco unt +1' result = '$ result + ( $ loopcou nt * 2) doneecho “ result is $ result ”例7:select item infinishSiten = "finish* |8 henI r* & d

15、Kndonestupci *£ text/.h1) continue2) flnisti#? 1#? 2stipd -* |8. 用vi编写例8及例9掌握条件语句的用 法,函数的用法,观察运行结果。i>1 inBl|0?|-»3|04例&假如给出月份数字作为参数编写程序displaymonth.h旳Iecho "MOnth is Jan"; echo "Month is Feb-1:;echo "MOnth i耳 Mar' echo HDnth is Apr-; "HQnxh is May";

16、 echo *MOnth is Jun";; ech« 'FKnth n Jul'«cho nonih is Aug-;El 筑"ho MOnth is Sep*:; ei«|ie| echo 'M&nth is Oct ; 011|11> echo 'Month is 他严; ?Q 机he "WOnth is Dtc-;: echo "invalid"tiSdCstuwci «| ul texra.h stulpcl *I texts h Invalid例9

17、:|displavKionth () <$1 in011iflecho "Month is Jan"?; 021曲呼ho "Month is F电b*; 93echo "Month is Har": B4|4| echo 'Month Is Apr*; l-fecho "Month Is May-;J3il 酗 aie|ie912|1296|EQ echo *Month is Jun" Etho "Manth Ls Jul": | ezho 'nor:h 15 Aua";

18、echo HH9nth 込 Sep' I echo "Hanth i耳 OctB; echo "Ktonth is Nov": | echo *Mqnth isPeC;-Q echo Invalid'esse displayraonth fl 叽 ayKnth 1Zs vi tuKtS-hstupcl 'ji texts.hMonth is AugMonth is Decsiu(?pci -1$ |9.编程,在屏幕上显示用户主目录名(HOME)、命令搜索路径(PATH),并显示由位 置参数指定的文件的类型和操作权限。stupd T$ vi text.h5tu卽cltextFhhome is /home/stuecho patn id /usr/Iocal/oin:/usr/bin:/bin:/usr/openmpi/tin:/opt/intet/compose rxe<bin: Zusr/local/sbin ; /u s r/s bin: /sbin: /honie/stu/binstupcl -)$ |体会:这次shell实验感觉有点难。在用vi编程结束后运行时总是有语法错误,因为对语法不太熟悉,因此在修改方面有很大的困难。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1