Advanced Bash-Scripting Guide

Advanced Bash-Scripting Guide

Advanced Bash-Scripting Guide An in-depth exploration of the art of shell scripting Mendel Cooper <[email protected]> 5.5 23 November 2008 Revision History Revision 5.3 05 May 2008 Revised by: mc 'GOLDENBERRY' release: Minor Update. Revision 5.4 21 July 2008 Revised by: mc 'ANGLEBERRY' release: Major Update. Revision 5.5 23 Nov 2008 Revised by: mc 'FARKLEBERRY' release: Minor Update. 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 nuggets 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. 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 and rendered HTML, may be downloaded from the author's home site. A pdf version is also available ( pdf mirror site). See the change log for a revision history. Dedication For Anita, the source of all the magic Advanced Bash-Scripting Guide Table of Contents Chapter 1. Why Shell Programming?...............................................................................................................1 Chapter 2. Starting Off With a Sha-Bang........................................................................................................3 2.1. Invoking the script............................................................................................................................6 2.2. Preliminary Exercises.......................................................................................................................6 Part 2. Basics.......................................................................................................................................................7 Chapter 3. Special Characters...........................................................................................................................8 Chapter 4. Introduction to Variables and Parameters..................................................................................28 4.1. Variable Substitution......................................................................................................................28 4.2. Variable Assignment.......................................................................................................................31 4.3. Bash Variables Are Untyped..........................................................................................................32 4.4. Special Variable Types...................................................................................................................33 Chapter 5. Quoting...........................................................................................................................................39 5.1. Quoting Variables...........................................................................................................................39 5.2. Escaping..........................................................................................................................................41 Chapter 6. Exit and Exit Status.......................................................................................................................47 Chapter 7. Tests................................................................................................................................................49 7.1. Test Constructs...............................................................................................................................49 7.2. File test operators............................................................................................................................56 7.3. Other Comparison Operators..........................................................................................................59 7.4. Nested if/then Condition Tests.......................................................................................................64 7.5. Testing Your Knowledge of Tests..................................................................................................65 Chapter 8. Operations and Related Topics....................................................................................................66 8.1. Operators.........................................................................................................................................66 8.2. Numerical Constants.......................................................................................................................72 Part 3. Beyond the Basics.................................................................................................................................74 Chapter 9. Variables Revisited........................................................................................................................75 9.1. Internal Variables............................................................................................................................75 9.2. Manipulating Strings.......................................................................................................................92 9.2.1. Manipulating strings using awk..........................................................................................100 9.2.2. Further Reference................................................................................................................100 9.3. Parameter Substitution..................................................................................................................101 9.4. Typing variables: declare or typeset.............................................................................................110 9.4.1. Another use for declare.......................................................................................................112 9.5. Indirect References.......................................................................................................................112 9.6. $RANDOM: generate random integer..........................................................................................116 9.7. The Double-Parentheses Construct...............................................................................................127 i Advanced Bash-Scripting Guide Table of Contents Chapter 10. Loops and Branches..................................................................................................................129 10.1. Loops..........................................................................................................................................129 10.2. Nested Loops..............................................................................................................................142 10.3. Loop Control...............................................................................................................................143 10.4. Testing and Branching................................................................................................................146 Chapter 11. Command Substitution.............................................................................................................155 Chapter 12. Arithmetic Expansion................................................................................................................161 Chapter 13. Recess Time................................................................................................................................162 Part 4. Commands..........................................................................................................................................163 Chapter 14. Internal Commands and Builtins.............................................................................................171 14.1. Job Control Commands..............................................................................................................199 Chapter 15. External Filters, Programs and Commands...........................................................................204 15.1. Basic Commands........................................................................................................................204 15.2. Complex Commands...................................................................................................................209 15.3. Time / Date Commands..............................................................................................................219 15.4. Text Processing Commands........................................................................................................223 15.5. File and Archiving Commands...................................................................................................245 15.6. Communications Commands......................................................................................................263 15.7. Terminal Control Commands.....................................................................................................277 15.8. Math Commands.........................................................................................................................278 15.9. Miscellaneous Commands..........................................................................................................289

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    813 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us