




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 物业杀虫防虫方案(3篇)
- 美术机构提价方案(3篇)
- 猪肉产品投标方案(3篇)
- 工程材料代用管理制度
- 公交广告企划方案(3篇)
- 园区搬迁预算方案(3篇)
- 工厂生产外包方案(3篇)
- 公司采购领用管理制度
- 培训学校自主管理制度
- 包装印刷公司管理制度
- DLT 593-2016 高压开关设备和控制设备
- 【MOOC】森林食品资源学-南京林业大学 中国大学慕课MOOC答案
- 【MOOC】微型计算机原理与接口技术-南京邮电大学 中国大学慕课MOOC答案
- 甘肃省陇南市多校2024-2025学年上学期期中检测七年级数学试卷(无答案)
- 中华人民共和国突发事件应对法培训课件
- 状元帽美术课件
- 脱硫检修工个人工作总结
- 内部工程项目承包合同范本
- 山西省2022年中考语文真题试卷(含答案)
- 甘肃省2024年中考生物试卷四套合卷【附答案】
- 民用无人机操控员执照(CAAC)备考复习题库-下部分(600题)
评论
0/150
提交评论