• Embed Doc
  • Readcast
  • Collections
  • 1
    CommentGo Back
Download
 
Advanced Bash−Scripting Guide
An in−depth exploration of the art of shell scripting
Mendel Cooper
<thegrendel@theriver.com>
3.003 October 2004
Revision History
Revision 2.718 April 2004Revised by: mc'MULBERRY' release: Minor update.Revision 2.811 July 2004Revised by: mc'ELDERBERRY' release: Minor update.Revision 3.003 Oct 2004Revised by: mc'LOGANBERRY' release: Major update.This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward anintermediate/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 shellscripting techniques. The exercises and heavily−commented examples invite active reader participation, underthe premise that
the only way to really learn scripting is to write scripts
.This book is suitable for classroom use as a general introduction to programming concepts.The latest update of this document, as an archived, bzip2−ed "tarball" including both the SGML source andrendered HTML, may be downloaded from the author's home site. A pdf version is also available. See thechange log for a revision history.
Dedication
For Anita, the source of all the magic
 
Table of Contents
Chapter 1. Why Shell Programming?...............................................................................................................1Chapter 2. Starting Off With a Sha−Bang.......................................................................................................3
2.1. Invoking the script............................................................................................................................62.2. Preliminary Exercises.......................................................................................................................6
Part 2. Basics.......................................................................................................................................................7Chapter 3. Special Characters...........................................................................................................................8Chapter 4. Introduction to Variables and Parameters..................................................................................25
4.1. Variable Substitution......................................................................................................................254.2. Variable Assignment.......................................................................................................................274.3. Bash Variables Are Untyped..........................................................................................................284.4. Special Variable Types...................................................................................................................30
Chapter 5. Quoting...........................................................................................................................................34Chapter 6. Exit and Exit Status.......................................................................................................................40Chapter 7. Tests................................................................................................................................................42
7.1. Test Constructs...............................................................................................................................427.2. File test operators............................................................................................................................487.3. Other Comparison Operators..........................................................................................................517.4. Nested if/then Condition Tests.......................................................................................................567.5. Testing Your Knowledgeof Tests..................................................................................................56
Chapter 8. Operations and Related Topics....................................................................................................58
8.1. Operators.........................................................................................................................................588.2. Numerical Constants.......................................................................................................................64
Part 3. Beyond the Basics.................................................................................................................................66Chapter 9. Variables Revisited........................................................................................................................67
9.1. Internal Variables............................................................................................................................679.2. Manipulating Strings.......................................................................................................................849.2.1. Manipulating strings using awk............................................................................................889.2.2. Further Discussion.................................................................................................................899.3. Parameter Substitution....................................................................................................................899.4. Typing variables: declare or typeset...............................................................................................979.5. Indirect References to Variables.....................................................................................................999.6. $RANDOM: generate random integer..........................................................................................1019.7. The DoubleParenthesesConstruct...............................................................................................110
Chapter 10. Loops andBranches..................................................................................................................112
10.1. Loops..........................................................................................................................................11210.2. Nested Loops..............................................................................................................................12310.3. Loop Control...............................................................................................................................123
Advanced Bash−Scripting Guidei
 
Table ofContents
Chapter 10. Loops and Branches
10.4. Testing and Branching................................................................................................................127
Chapter 11. Internal Commands and Builtins.............................................................................................134
11.1. Job Control Commands..............................................................................................................156
Chapter 12. External Filters, Programs and Commands...........................................................................161
12.1. Basic Commands........................................................................................................................16112.2. Complex Commands...................................................................................................................16512.3. Time / Date Commands..............................................................................................................17412.4. Text Processing Commands........................................................................................................17712.5. File and Archiving Commands...................................................................................................19412.6. Communications Commands......................................................................................................20812.7. Terminal Control Commands.....................................................................................................21712.8. Math Commands.........................................................................................................................21812.9. Miscellaneous Commands..........................................................................................................227
Chapter 13. System and Administrative Commands..................................................................................237Chapter 14. Command Substitution.............................................................................................................261Chapter 15. ArithmeticExpansion................................................................................................................266Chapter 16. I/O Redirection...........................................................................................................................267
16.1. Using exec...................................................................................................................................26916.2. Redirecting Code Blocks............................................................................................................27316.3. Applications................................................................................................................................277
Chapter 17. Here Documents.........................................................................................................................279
17.1. Here Strings................................................................................................................................287
Chapter 18. Recess Time................................................................................................................................289Part 4. Advanced Topics.................................................................................................................................290Chapter 19. Regular Expressions..................................................................................................................291
19.1. ABrief Introduction to Regular Expressions..............................................................................29119.2. Globbing.....................................................................................................................................294
Chapter 20. Subshells.....................................................................................................................................296Chapter 21. Restricted Shells.........................................................................................................................299Chapter 22. Process Substitution...................................................................................................................301Chapter 23. Functions....................................................................................................................................304
23.1. Complex Functions and Function Complexities.........................................................................30623.2. Local Variables...........................................................................................................................315
Advanced Bash−Scripting Guideii
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
10 / 06 / 2010<span class="translation_missing">en_US, this_document_made_it_onto_the</span>Rising List!
You must be to leave a comment.
Submit
Characters: ...