没有合适的资源?快使用搜索试试~ 我知道了~
An in−depth exploration of the art of shell scriptingBugs fixed, plus much addit
资源推荐
资源详情
资源评论
Advanced Bash−Scripting Guide
An in−depth exploration of the art of shell scripting
Mendel Cooper
1.9
21 June 2003
Revision History
Revision 0.1 14 June 2000 Revised by: mc
Initial release.
Revision 0.2 30 October 2000 Revised by: mc
Bugs fixed, plus much additional material and more example scripts.
Revision 0.3 12 February 2001 Revised by: mc
Another major update.
Revision 0.4 08 July 2001 Revised by: mc
More bugfixes, much more material, more scripts − a complete revision and expansion of the book.
Revision 0.5 03 September 2001 Revised by: mc
Major update. Bugfixes, material added, chapters and sections reorganized.
Revision 1.0 14 October 2001 Revised by: mc
Bugfixes, reorganization, material added. Stable release.
Revision 1.1 06 January 2002 Revised by: mc
Bugfixes, material and scripts added.
Revision 1.2 31 March 2002 Revised by: mc
Bugfixes, material and scripts added.
Revision 1.3 02 June 2002 Revised by: mc
'TANGERINE' release: A few bugfixes, much more material and scripts added.
Revision 1.4 16 June 2002 Revised by: mc
'MANGO' release: Quite a number of typos fixed, more material and scripts added.
Revision 1.5 13 July 2002 Revised by: mc
'PAPAYA' release: A few bugfixes, much more material and scripts added.
Revision 1.6 29 September 2002 Revised by: mc
'POMEGRANATE' release: some bugfixes, more material, one more script added.
Revision 1.7 05 January 2003 Revised by: mc
'COCONUT' release: a couple of bugfixes, more material, one more script.
Revision 1.8 10 May 2003 Revised by: mc
'BREADFRUIT' release: a number of bugfixes, more scripts and material.
Revision 1.9 21 June 2003 Revised by: mc
'PERSIMMON' release: bugfixes and more material.
This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an
intermediate/advanced level of instruction . . . all the while sneaking in little snippets of UNIX wisdom and
lore. It serves as a textbook, a manual for self−study, and a reference and source of knowledge on shell
scripting techniques. The exercises and heavily−commented examples invite active reader participation, under
the premise that the only way to really learn scripting is to write scripts.
The latest update of this document, as an archived, bzip2−ed "tarball" including both the SGML source and
rendered HTML, may be downloaded from the author's home site. See the change log for a revision history.
Dedication
For Anita, the source of all the magic
Table of Contents
Chapter 1. Why Shell Programming?...............................................................................................................1
Chapter 2. Starting Off With a Sha−Bang.......................................................................................................3
2.1. Invoking the script............................................................................................................................5
2.2. Preliminary Exercises.......................................................................................................................5
Part 2. Basics.......................................................................................................................................................6
Chapter 3. Special Characters...........................................................................................................................7
Chapter 4. Introduction to Variables and Parameters..................................................................................23
4.1. Variable Substitution......................................................................................................................23
4.2. Variable Assignment.......................................................................................................................25
4.3. Bash Variables Are Untyped..........................................................................................................26
4.4. Special Variable Types...................................................................................................................28
Chapter 5. Quoting...........................................................................................................................................32
Chapter 6. Exit and Exit Status.......................................................................................................................38
Chapter 7. Tests................................................................................................................................................40
7.1. Test Constructs...............................................................................................................................40
7.2. File test operators............................................................................................................................46
7.3. Comparison operators (binary).......................................................................................................49
7.4. Nested if/then Condition Tests.......................................................................................................54
7.5. Testing Your Knowledge of Tests..................................................................................................54
Chapter 8. Operations and Related Topics....................................................................................................55
8.1. Operators.........................................................................................................................................55
8.2. Numerical Constants.......................................................................................................................61
Part 3. Beyond the Basics.................................................................................................................................63
Chapter 9. Variables Revisited........................................................................................................................64
9.1. Internal Variables............................................................................................................................64
9.2. Manipulating Strings.......................................................................................................................79
9.2.1. Manipulating strings using awk............................................................................................83
9.2.2. Further Discussion.................................................................................................................84
9.3. Parameter Substitution....................................................................................................................84
9.4. Typing variables: declare or typeset...............................................................................................92
9.5. Indirect References to Variables.....................................................................................................94
9.6. $RANDOM: generate random integer............................................................................................96
9.7. The Double Parentheses Construct...............................................................................................101
Chapter 10. Loops and Branches..................................................................................................................103
10.1. Loops..........................................................................................................................................103
10.2. Nested Loops..............................................................................................................................113
10.3. Loop Control...............................................................................................................................114
Advanced Bash−Scripting Guide
i
Table of Contents
Chapter 10. Loops and Branches
10.4. Testing and Branching................................................................................................................117
Chapter 11. Internal Commands and Builtins.............................................................................................124
11.1. Job Control Commands..............................................................................................................144
Chapter 12. External Filters, Programs and Commands...........................................................................148
12.1. Basic Commands........................................................................................................................148
12.2. Complex Commands...................................................................................................................151
12.3. Time / Date Commands..............................................................................................................158
12.4. Text Processing Commands........................................................................................................160
12.5. File and Archiving Commands...................................................................................................176
12.6. Communications Commands......................................................................................................191
12.7. Terminal Control Commands.....................................................................................................195
12.8. Math Commands.........................................................................................................................196
12.9. Miscellaneous Commands..........................................................................................................204
Chapter 13. System and Administrative Commands..................................................................................214
Chapter 14. Command Substitution.............................................................................................................236
Chapter 15. Arithmetic Expansion................................................................................................................241
Chapter 16. I/O Redirection...........................................................................................................................242
16.1. Using exec...................................................................................................................................244
16.2. Redirecting Code Blocks............................................................................................................247
16.3. Applications................................................................................................................................251
Chapter 17. Here Documents.........................................................................................................................253
Chapter 18. Recess Time................................................................................................................................260
Part 4. Advanced Topics.................................................................................................................................261
Chapter 19. Regular Expressions..................................................................................................................262
19.1. A Brief Introduction to Regular Expressions..............................................................................262
19.2. Globbing.....................................................................................................................................265
Chapter 20. Subshells.....................................................................................................................................267
Chapter 21. Restricted Shells.........................................................................................................................270
Chapter 22. Process Substitution...................................................................................................................272
Chapter 23. Functions....................................................................................................................................274
23.1. Complex Functions and Function Complexities.........................................................................276
23.2. Local Variables...........................................................................................................................283
23.2.1. Local variables make recursion possible...........................................................................284
Advanced Bash−Scripting Guide
ii
Table of Contents
Chapter 24. Aliases.........................................................................................................................................286
Chapter 25. List Constructs...........................................................................................................................289
Chapter 26. Arrays.........................................................................................................................................292
Chapter 27. Files.............................................................................................................................................311
Chapter 28. /dev and /proc.............................................................................................................................312
28.1. /dev..............................................................................................................................................312
28.2. /proc............................................................................................................................................312
Chapter 29. Of Zeros and Nulls.....................................................................................................................317
Chapter 30. Debugging...................................................................................................................................320
Chapter 31. Options........................................................................................................................................326
Chapter 32. Gotchas.......................................................................................................................................328
Chapter 33. Scripting With Style..................................................................................................................334
33.1. Unofficial Shell Scripting Stylesheet..........................................................................................334
Chapter 34. Miscellany...................................................................................................................................337
34.1. Interactive and non−interactive shells and scripts......................................................................337
34.2. Shell Wrappers............................................................................................................................338
34.3. Tests and Comparisons: Alternatives..........................................................................................341
34.4. Recursion....................................................................................................................................342
34.5. "Colorizing" Scripts....................................................................................................................343
34.6. Optimizations..............................................................................................................................347
34.7. Assorted Tips..............................................................................................................................348
34.8. Security Issues............................................................................................................................355
34.9. Portability Issues.........................................................................................................................355
34.10. Shell Scripting Under Windows...............................................................................................356
Chapter 35. Bash, version 2...........................................................................................................................357
Chapter 36. Endnotes.....................................................................................................................................362
36.1. Author's Note..............................................................................................................................362
36.2. About the Author........................................................................................................................362
36.3. Tools Used to Produce This Book..............................................................................................362
36.3.1. Hardware...........................................................................................................................362
36.3.2. Software and Printware.....................................................................................................362
36.4. Credits.........................................................................................................................................363
Bibliography....................................................................................................................................................365
Advanced Bash−Scripting Guide
iii
剩余453页未读,继续阅读
资源评论
邢小鹏
- 粉丝: 24
- 资源: 327
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功