版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、<p><b> 附 錄</b></p><p> 外文資料翻譯原文部分</p><p> Advanced Bash-Scripting Guide</p><p> An in-depth exploration of the art of shell scripting</p><p> 1.
2、Introduction</p><p> The shell is a command interpreter. More than just the insulating layer between the operating system kernel and the user, it's also a fairly powerful programming language. A shell p
3、rogram, called a script, is an easy-to-use tool for building applications by "gluing" together system calls, tools, utilities, and compiled binaries. Virtually the entire repertoire of UNIX commands, utilities,
4、 and tools is available for invocation by a shell script. If that were not enough, internal shell commands, s</p><p> 2. Why Shell Programming?</p><p> A working knowledge of shell scripting i
5、s essential to anyone wishing to become reasonably proficient at system administration, even if they do not anticipate ever having to actually write a script. Consider that as a Linux machine boots up, it executes the sh
6、ell scripts in /etc/rc.d to restore the system configuration and set up services. A detailed understanding of these startup scripts is important for analyzing the behavior of a system, and possibly modifying it.</p>
7、;<p> Writing shell scripts is not hard to learn, since the scripts can be built in bite-sized sections and there is only a fairly small set of shell-specific operators and options to learn. The syntax is simple
8、 and straightforward, similar to that of invoking and chaining together utilities at the command line, and there are only a few "rules" to learn. Most short scripts work right the first time, and debugging even
9、 the longer ones is straightforward.</p><p> A shell script is a "quick and dirty" method of prototyping a complex application. Getting even a limited subset of the functionality to work in a shel
10、l script is often a useful first stage in project development. This way, the structure of the application can be tested and played with, and the major pitfalls found before proceeding to the final coding in C, C++, Java,
11、 or Perl.</p><p> Shell scripting hearkens back to the classic UNIX philosophy of breaking complex projects into simpler subtasks, of chaining together components and utilities. Many consider this a better,
12、 or at least more esthetically pleasing approach to problem solving than using one of the new generation of high powered all-in-one languages, such as Perl, which attempt to be all things to all people, but at the cost o
13、f forcing you to alter your thinking processes to fit the tool.</p><p> When not to use shell scripts </p><p> Resource-intensive tasks, especially where speed is a factor (sorting, hashing, e
14、tc.)</p><p> Procedures involving heavy-duty math operations, especially floating point arithmetic, arbitrary precision calculations, or complex numbers (use C++ or FORTRAN instead)</p><p> Cr
15、oss-platform portability required (use C or Java instead)</p><p> Complex applications, where structured programming is a necessity (need type-checking of variables, function prototypes, etc.)</p>&l
16、t;p> Mission-critical applications upon which you are betting the ranch, or the future of the company</p><p> Situations where security is important, where you need to guarantee the integrity of your sy
17、stem and protect against intrusion, cracking, and vandalism</p><p> Project consists of subcomponents with interlocking dependencies</p><p> Extensive file operations required (Bash is limited
18、 to serial file access, and that only in a particularly clumsy and inefficient line-by-line fashion)</p><p> Need native support for multi-dimensional arrays</p><p> Need data structures, such
19、 as linked lists or trees</p><p> Need to generate or manipulate graphics or GUIs</p><p> Need direct access to system hardware</p><p> Need port or socket I/O</p><p&g
20、t; Need to use libraries or interface with legacy code</p><p> Proprietary, closed-source applications (shell scripts put the source code right out in the open for all the world to see)</p><p>
21、; If any of the above applies, consider a more powerful scripting language -- perhaps Perl, Tcl, Python, Ruby -- or possibly a high-level compiled language such as C, C++, or Java. Even then, prototyping the application
22、 as a shell script might still be a useful development step.</p><p> We will be using Bash, an acronym for "Bourne-Again shell" and a pun on Stephen Bourne's now classic Bourne shell. Bash has
23、 become a de facto standard for shell scripting on all flavors of UNIX. Most of the principles this book covers apply equally well to scripting with other shells, such as the Korn Shell, from which Bash derives some of i
24、ts features, and the C Shell and its variants. (Note that C Shell programming is not recommended due to certain inherent problems, as pointed out in an Octob</p><p> What follows is a tutorial on shell scri
25、pting. It relies heavily on examples to illustrate various features of the shell. The example scripts work -- they've been tested, insofar as was possible -- and some of them are even useful in real life. The reader
26、can play with the actual working code of the examples in the source archive (scriptname.sh or scriptname.bash), give them execute permission (chmod u+rx scriptname), then run them to see what happens. Should the source a
27、rchive not be available,</p><p> 外文資料翻譯譯文部分</p><p> 高級Bash腳本編程指南</p><p> 一個對腳本編程技術(shù)的深入討論</p><p><b> 1:簡介</b></p><p> Shell是一個命令解釋器。它是操作系統(tǒng)內(nèi)核
28、和用戶之間的絕緣層,也是一種功能強(qiáng)大的編程語言。一個Shell程序,通常被稱作為腳本,它是由系統(tǒng)調(diào)用,命令工具,軟件包和已編譯的二進(jìn)制包"結(jié)合" 起來的容易使用的工具。事實(shí)上,shell腳本可以調(diào)用整個UNIX系統(tǒng)命令,軟件包和工具。如果這還不太夠的話,Shell的內(nèi)部命令,如測試和循環(huán)結(jié)構(gòu),都使得Shell腳本更強(qiáng)大和更有彈性。Shell腳本在管理系統(tǒng)任務(wù)中表現(xiàn)得非常出色,在對日常反復(fù)性的處理工作中避免使用那些結(jié)構(gòu)
29、復(fù)雜的程序語言。</p><p> 2:為什么要用Shell編程?</p><p> 腳本應(yīng)用知識對希望精通系統(tǒng)管理的任何個人說是必需的,他實(shí)際上不想寫一個腳本程序。一般說一個Linux機(jī)器啟動后,它會執(zhí)行在/etc/rc.d 目錄下的Shell腳本重建系統(tǒng)環(huán)境并且啟動各種服務(wù)。理解這些啟動腳本的細(xì)節(jié)對分析系統(tǒng)運(yùn)作并修改它是有很大意義的。</p><p> 編
30、寫shell腳本并不難學(xué),因?yàn)槟_本內(nèi)建的功能集(check?)和他們只要學(xué)相當(dāng)少的shell的操作符和選項(xiàng)。語法簡單易懂,像在命令行上調(diào)用和連接軟件包那樣容易,它只有少量的 "規(guī)則" 需要掌握。大多數(shù)短小的腳本第一次就工作的很好,較長的腳本調(diào)試也相當(dāng)?shù)娜菀住?lt;/p><p> shell腳本是個復(fù)雜應(yīng)用原型的"quick and dirty" 方法。在項(xiàng)目開發(fā)中用shel
31、l編程實(shí)現(xiàn)個有限的功能性子集是有用的開始。用這種方法去測試應(yīng)用程序的結(jié)構(gòu)和模塊組合,可以在實(shí)際地用C,C++,Java或者Perl進(jìn)行編程之前發(fā)現(xiàn)主要的設(shè)計(jì)缺陷。</p><p> Shell編程遵從經(jīng)典UNIX哲學(xué):把復(fù)雜的問題分成簡單的小問題,然后再把各部分功能組合起來解決復(fù)雜問題。這和用新一代高級的多用途的語言,例如Perl,試圖成為所有人處理所有事情的語言但是所付出的代價(jià)是強(qiáng)迫改變你的思維方法來適應(yīng)這種
32、工具,大多數(shù)人認(rèn)為這是一個更好的或者至少感覺上更令人能接受的方法。</p><p> 什么時(shí)候不適合使用Shell編程: </p><p> 資源緊張的項(xiàng)目,特別是速度是重要因素的地方(排序,散序,等等)</p><p> 程序要進(jìn)行很復(fù)雜的數(shù)學(xué)計(jì)算,特別是浮點(diǎn)計(jì)算,任意精度的計(jì)算,或者是復(fù)數(shù)計(jì)算(應(yīng)該用C++或是FORTRAN代替)</p>&
33、lt;p> 要求交叉編譯平臺的可移植性(使用C或者是Java代替)</p><p> 需要結(jié)構(gòu)化編程的復(fù)雜應(yīng)用(需要變量類型檢查和函數(shù)原型等等)</p><p> 對于影響系統(tǒng)全局性的關(guān)鍵任務(wù)應(yīng)用。</p><p> 安全非常重要。你必須保證系統(tǒng)完整性和抵抗入侵,攻擊和惡意破壞。</p><p> 項(xiàng)目由連串的依賴的各個部分組
34、成。</p><p> 多種文件操作要求(Bash被限制成文件順序存取,并且是以相當(dāng)笨拙,效率低下的逐行的存取方式)</p><p> 需要良好的多維數(shù)組支持。</p><p> 需要類似鏈表或樹這樣的數(shù)據(jù)結(jié)構(gòu)。</p><p> 需要產(chǎn)生或操作圖象或圖形用戶界面。</p><p> 需要直接存取系統(tǒng)硬件。&
35、lt;/p><p> 需要端口號或是socket I/O。</p><p> 需要使用可重用的函數(shù)庫或接口。</p><p> 所有的私有的不開源的應(yīng)用程序(Shell腳本的源代碼是直接可讀,能被所有人看到的)</p><p> 如果你需要有上面的任意一種應(yīng)用,請考慮其他的更強(qiáng)大的腳本語言――Perl,Tcl,Python,Ruby,或者
36、可能是其他更高級的編譯型語言,例如C,C++或者是Java。盡管如此,使用Shell腳本來構(gòu)造應(yīng)用原型仍然是一個有用的開發(fā)步驟。</p><p> 我們將會使用Bash,它是 "Bourne-Again shell" 的首字母縮寫,并且是Setphen Bourne寫的經(jīng)典的Bourne shell的同義詞。Bash已經(jīng)變成了所有令人喜歡的UNIX上shell編程 事實(shí)的上的 這本書的大多數(shù)
37、腳本技術(shù)能很好的應(yīng)用到其他的Shell當(dāng)中,比如說Korn Shell,Bash借用了它的一些特性, 還有C Shell和他的不同之處。(注意:C shell編程不是交付一定的內(nèi)在問題,這點(diǎn)已由Tom Christiansen在1993年10月在 Usenet post 被指出了) </p><p> 接下來是的是一篇腳本的指南。它由許多的例子來引出Shell的許多特性。這些已經(jīng)被測試過的例子不僅能工作,并且可
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 高級bash腳本編程指南
- linux_bash腳本編程大全
- 高級編程技術(shù)
- vbs腳本編程簡明教程
- windows腳本編程核心技術(shù)精解-隨書示例腳本-第五章
- 基礎(chǔ)技能訓(xùn)練高級軟件編程技術(shù)
- javaweb編程技術(shù)
- matlab第五講編程基礎(chǔ)i(腳本)
- linux_shell(腳本)編程入門_實(shí)例講解詳解
- 電大《數(shù)控編程技術(shù)》題庫
- 一個家庭理財(cái)指南【外文翻譯】
- 談?wù)刬os網(wǎng)絡(luò)編程之socket編程技術(shù)及應(yīng)用
- 外文翻譯--基于制造特征的三軸高速銑削數(shù)控自動編程技術(shù)
- 數(shù)控編程技術(shù)作業(yè)答1
- 網(wǎng)絡(luò)編程技術(shù)課程研究
- 實(shí)驗(yàn)二、三jsp編程技術(shù)
- plc可編程技術(shù)題庫
- 數(shù)控編程技術(shù)的現(xiàn)狀與發(fā)展
- 數(shù)控編程技術(shù)畢業(yè)論文
- jsp應(yīng)用課件—web編程技術(shù)
評論
0/150
提交評論