已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
附录外文资料翻译原文部分AdvancedBash-ScriptingGuideAnin-depthexplorationoftheartofshellscripting1.IntroductionTheshellisacommandinterpreter.Morethanjusttheinsulatinglayerbetweentheoperatingsystemkernelandtheuser,itsalsoafairlypowerfulprogramminglanguage.Ashellprogram,calledascript,isaneasy-to-usetoolforbuildingapplicationsbygluingtogethersystemcalls,tools,utilities,andcompiledbinaries.VirtuallytheentirerepertoireofUNIXcommands,utilities,andtoolsisavailableforinvocationbyashellscript.Ifthatwerenotenough,internalshellcommands,suchastestingandloopconstructs,giveadditionalpowerandflexibilitytoscripts.Shellscriptslendthemselvesexceptionallywelltoadministrativesystemtasksandotherroutinerepetitivejobsnotrequiringthebellsandwhistlesofafull-blowntightlystructuredprogramminglanguage.2.WhyShellProgramming?Aworkingknowledgeofshellscriptingisessentialtoanyonewishingtobecomereasonablyproficientatsystemadministration,eveniftheydonotanticipateeverhavingtoactuallywriteascript.ConsiderthatasaLinuxmachinebootsup,itexecutestheshellscriptsin/etc/rc.dtorestorethesystemconfigurationandsetupservices.Adetailedunderstandingofthesestartupscriptsisimportantforanalyzingthebehaviorofasystem,andpossiblymodifyingit.Writingshellscriptsisnothardtolearn,sincethescriptscanbebuiltinbite-sizedsectionsandthereisonlyafairlysmallsetofshell-specificoperatorsandoptionstolearn.Thesyntaxissimpleandstraightforward,similartothatofinvokingandchainingtogetherutilitiesatthecommandline,andthereareonlyafewrulestolearn.Mostshortscriptsworkrightthefirsttime,anddebuggingeventhelongeronesisstraightforward.Ashellscriptisaquickanddirtymethodofprototypingacomplexapplication.Gettingevenalimitedsubsetofthefunctionalitytoworkinashellscriptisoftenausefulfirststageinprojectdevelopment.Thisway,thestructureoftheapplicationcanbetestedandplayedwith,andthemajorpitfallsfoundbeforeproceedingtothefinalcodinginC,C+,Java,orPerl.ShellscriptinghearkensbacktotheclassicUNIXphilosophyofbreakingcomplexprojectsintosimplersubtasks,ofchainingtogethercomponentsandutilities.Manyconsiderthisabetter,oratleastmoreestheticallypleasingapproachtoproblemsolvingthanusingoneofthenewgenerationofhighpoweredall-in-onelanguages,suchasPerl,whichattempttobeallthingstoallpeople,butatthecostofforcingyoutoalteryourthinkingprocessestofitthetool.WhennottouseshellscriptsResource-intensivetasks,especiallywherespeedisafactor(sorting,hashing,etc.)Proceduresinvolvingheavy-dutymathoperations,especiallyfloatingpointarithmetic,arbitraryprecisioncalculations,orcomplexnumbers(useC+orFORTRANinstead)Cross-platformportabilityrequired(useCorJavainstead)Complexapplications,wherestructuredprogrammingisanecessity(needtype-checkingofvariables,functionprototypes,etc.)Mission-criticalapplicationsuponwhichyouarebettingtheranch,orthefutureofthecompanySituationswheresecurityisimportant,whereyouneedtoguaranteetheintegrityofyoursystemandprotectagainstintrusion,cracking,andvandalismProjectconsistsofsubcomponentswithinterlockingdependenciesExtensivefileoperationsrequired(Bashislimitedtoserialfileaccess,andthatonlyinaparticularlyclumsyandinefficientline-by-linefashion)Neednativesupportformulti-dimensionalarraysNeeddatastructures,suchaslinkedlistsortreesNeedtogenerateormanipulategraphicsorGUIsNeeddirectaccesstosystemhardwareNeedportorsocketI/ONeedtouselibrariesorinterfacewithlegacycodeProprietary,closed-sourceapplications(shellscriptsputthesourcecoderightoutintheopenforalltheworldtosee)Ifanyoftheaboveapplies,consideramorepowerfulscriptinglanguage-perhapsPerl,Tcl,Python,Ruby-orpossiblyahigh-levelcompiledlanguagesuchasC,C+,orJava.Eventhen,prototypingtheapplicationasashellscriptmightstillbeausefuldevelopmentstep.WewillbeusingBash,anacronymforBourne-AgainshellandapunonStephenBournesnowclassicBourneshell.BashhasbecomeadefactostandardforshellscriptingonallflavorsofUNIX.Mostoftheprinciplesthisbookcoversapplyequallywelltoscriptingwithothershells,suchastheKornShell,fromwhichBashderivessomeofitsfeatures,andtheCShellanditsvariants.(NotethatCShellprogrammingisnotrecommendedduetocertaininherentproblems,aspointedoutinanOctober,1993UsenetpostbyTomChristiansen.)Whatfollowsisatutorialonshellscripting.Itreliesheavilyonexamplestoillustratevariousfeaturesoftheshell.Theexamplescriptswork-theyvebeentested,insofaraswaspossible-andsomeofthemareevenusefulinreallife.Thereadercanplaywiththeactualworkingcodeoftheexamplesinthesourcearchive(scriptname.shorscriptname.bash),givethemexecutepermission(chmodu+rxscriptname),thenrunthemtoseewhathappens.Shouldthesourcearchivenotbeavailable,thencut-and-pastefromtheHTML,pdf,ortextrenderedversions.Beawarethatsomeofthescriptspresentedhereintroducefeaturesbeforetheyareexplained,andthismayrequirethereadertotemporarilyskipaheadforenlightenment.外文资料翻译译文部分高级Bash脚本编程指南一个对脚本编程技术的深入讨论1:简介Shell是一个命令解释器。它是操作系统内核和用户之间的绝缘层,也是一种功能强大的编程语言。一个Shell程序,通常被称作为脚本,它是由系统调用,命令工具,软件包和已编译的二进制包结合起来的容易使用的工具。事实上,shell脚本可以调用整个UNIX系统命令,软件包和工具。如果这还不太够的话,Shell的内部命令,如测试和循环结构,都使得Shell脚本更强大和更有弹性。Shell脚本在管理系统任务中表现得非常出色,在对日常反复性的处理工作中避免使用那些结构复杂的程序语言。2:为什么要用Shell编程?脚本应用知识对希望精通系统管理的任何个人说是必需的,他实际上不想写一个脚本程序。一般说一个Linux机器启动后,它会执行在/etc/rc.d目录下的Shell脚本重建系统环境并且启动各种服务。理解这些启动脚本的细节对分析系统运作并修改它是有很大意义的。编写shell脚本并不难学,因为脚本内建的功能集(check?)和他们只要学相当少的shell的操作符和选项。语法简单易懂,像在命令行上调用和连接软件包那样容易,它只有少量的规则需要掌握。大多数短小的脚本第一次就工作的很好,较长的脚本
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 一例止血带放气不全导致的不良事件
- 三年级数学两位数乘两位数笔算题同步检测习题大全附答案
- 两位数加两位数计算单元练习训练题带答案
- 省级林木种苗示范基地建设项目可行性研究报告
- 2024年03月广东省惠东县2024年度赴高校公开招聘公办学校教师(湖南师范大学专场)43笔试参考题库附带答案详解
- 2024年03月四川省合江县人力资源和社会保障局2024年上半年公开考试招聘13名事业单位工作人员14笔试参考题库附带答案详解
- 2024年02月陕西省咸阳市事业单位2024年公开招考(募)1176名工作人员笔试参考题库附带答案详解
- 2024年02月贵州省铜仁市市直事业单位2024年公开招考72名工作人员笔试参考题库附带答案详解
- 2024年02月福建省松溪县2024年公开招聘31名新任教师2003笔试参考题库后附答案详解
- 2023年新疆物理中考(文字版)
- 4、主机房安全风险告知卡
- 昌平矿业公司工程质量监理评估报告
- 废旧锂离子电池回收利用技术应用环保主题PPT
- 《航空运输安全管理研究3600字(论文)》
- 2023年鄂尔多斯市东胜区体育教师招聘笔试模拟试题及答案
- 自考02316计算机应用技术-自考复习资料
- GB/T 27428-2022植物生物安全实验室通用要求
- GB/T 9739-2006化学试剂铁测定通用方法
- GB/T 31433-2015建筑幕墙、门窗通用技术条件
- 12YJ8 楼梯标准图集
- 2023年湖南省普通高中学业水平考试数学试卷及答案
评论
0/150
提交评论