外文翻译--高级Bash脚本编程指南一个对脚本编程技术的深入讨论.doc_第1页
外文翻译--高级Bash脚本编程指南一个对脚本编程技术的深入讨论.doc_第2页
外文翻译--高级Bash脚本编程指南一个对脚本编程技术的深入讨论.doc_第3页
外文翻译--高级Bash脚本编程指南一个对脚本编程技术的深入讨论.doc_第4页
外文翻译--高级Bash脚本编程指南一个对脚本编程技术的深入讨论.doc_第5页
已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论