已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 公租房小区建设项目可行性研究报告
- 富硒功能性产品和特膳食品加工关键技术研究及产业化应用项目可行性研究报告
- 技术中心创新能力提升项目可行性研究报告
- OLED显示材料及其他功能性材料项目可行性研究报告
- 三年级数学100以内整数除法计算题评价试题题带答案
- 小学二年级数学100以内加减法竖式计算单元自测试题带答案
- 江苏省无锡市重点达标名校2024年中考英语押题试卷含答案
- 江苏省无锡市宜兴外国语学校2023-2024学年中考英语对点突破模拟试卷含答案
- 2024年安神补脑类药物项目融资计划书
- 2024年高尔夫球车项目创业投资方案
- 肺动脉高压靶向药物治疗的中国证据
- 小眼睛大手术-眼科显微手术技能智慧树知到期末考试答案2024年
- 应急救援队组建方案
- 前列腺癌2024治疗指南
- 《民法典》答题题库100题
- 理综-试题和答案【2024届高考理综考向核心卷(全国地区专用)】
- 3完整版本.1-导游的仪容仪表礼仪课件《导游业务》(第五版)
- 岩板采购合同2024版
- 《摄影测量与遥感》课程标准(含课程思政)
- 2024-2030年中国网络文学行业市场深度研究及发展趋势预测报告
- GB/T 22849-2024针织T恤衫
评论
0/150
提交评论