- •Advanced Bash-Scripting Guide
- •Dedication
- •Table of Contents
- •Part 1. Introduction
- •Advanced Bash-Scripting Guide
- •Chapter 2. Starting Off With a Sha-Bang
- •2.1. Invoking the script
- •2.2. Preliminary Exercises
- •Part 2. Basics
- •Chapter 3. Exit and Exit Status
- •Chapter 4. Special Characters
- •Chapter 5. Introduction to Variables and Parameters
- •5.1. Variable Substitution
- •5.2. Variable Assignment
- •5.3. Bash Variables Are Untyped
- •5.4. Special Variable Types
- •Chapter 6. Quoting
- •Chapter 7. Tests
- •7.1. Test Constructs
- •7.2. File test operators
- •7.3. Comparison operators (binary)
- •7.4. Nested if/then Condition Tests
- •7.5. Testing Your Knowledge of Tests
- •8.1. Operators
- •8.2. Numerical Constants
- •Part 3. Beyond the Basics
- •Chapter 9. Variables Revisited
- •9.1. Internal Variables
- •9.2. Manipulating Strings
- •9.3. Parameter Substitution
- •9.4. Typing variables: declare or typeset
- •9.5. Indirect References to Variables
- •9.6. $RANDOM: generate random integer
- •9.7. The Double Parentheses Construct
- •Chapter 10. Loops and Branches
- •10.1. Loops
- •10.2. Nested Loops
- •10.3. Loop Control
- •10.4. Testing and Branching
- •Chapter 11. Internal Commands and Builtins
- •12.1. Basic Commands
- •12.2. Complex Commands
- •12.3. Time / Date Commands
- •12.4. Text Processing Commands
- •12.5. File and Archiving Commands
- •12.6. Communications Commands
- •12.7. Terminal Control Commands
- •12.8. Math Commands
- •12.9. Miscellaneous Commands
- •Chapter 13. System and Administrative Commands
- •Chapter 14. Command Substitution
- •Chapter 15. Arithmetic Expansion
- •Chapter 16. I/O Redirection
- •16.1. Using exec
- •16.2. Redirecting Code Blocks
- •16.3. Applications
- •Chapter 17. Here Documents
- •Chapter 18. Recess Time
- •Part 4. Advanced Topics
- •Chapter 19. Regular Expressions
- •19.1. A Brief Introduction to Regular Expressions
- •19.2. Globbing
- •Chapter 20. Subshells
- •Chapter 21. Restricted Shells
- •Chapter 22. Process Substitution
- •Chapter 23. Functions
- •23.1. Complex Functions and Function Complexities
- •23.2. Local Variables
- •Chapter 24. Aliases
- •Chapter 25. List Constructs
- •Chapter 26. Arrays
- •Chapter 27. Files
- •Chapter 28. /dev and /proc
- •28.2. /proc
- •Chapter 29. Of Zeros and Nulls
- •Chapter 30. Debugging
- •Chapter 31. Options
- •Chapter 32. Gotchas
- •Chapter 33. Scripting With Style
- •Chapter 34. Miscellany
- •34.2. Shell Wrappers
- •34.3. Tests and Comparisons: Alternatives
- •34.4. Optimizations
- •34.5. Assorted Tips
- •34.6. Oddities
- •34.7. Security Issues
- •34.8. Portability Issues
- •34.9. Shell Scripting Under Windows
- •Chapter 35. Bash, version 2
- •36. Endnotes
- •36.1. Author's Note
- •36.2. About the Author
- •36.3. Tools Used to Produce This Book
- •36.4. Credits
- •List of Tables
- •List of Examples
- •Bibliography
Miscellany
|
Advanced Bash-Scripting Guide: |
Prev |
Next |
Chapter 34. Miscellany
Nobody really knows what the Bourne shell's grammar is. Even examination of the source code is little help.
Tom Duff
Table of Contents
34.1.Interactive and non-interactive shells and scripts
34.2.Shell Wrappers
34.3.Tests and Comparisons: Alternatives
34.4.Optimizations
34.5.Assorted Tips
34.6.Oddities
34.7.Security Issues
34.8.Portability Issues
34.9.Shell Scripting Under Windows
Prev |
Home |
Next |
Unofficial Shell Scripting |
Up |
Interactive and non- |
Stylesheet |
|
interactive shells and scripts |
http://tldp.org/LDP/abs/html/miscellany.html [7/15/2002 6:34:41 PM]
Author's Note
|
Advanced Bash-Scripting Guide: |
|
Prev |
Chapter 36. Endnotes |
Next |
36.1. Author's Note
How did I come to write a Bash scripting book? It's a strange tale. It seems that a couple of years back, I needed to learn shell scripting -- and what better way to do that than to read a good book on the subject? I was looking to buy a tutorial and reference covering all aspects of the subject. I was looking for a book that would take difficult concepts, turn them inside out, and explain them in excruciating detail with well-commented examples. [1] In fact, I was looking for this very book, or something much like it. Unfortunately, it didn't exist, and if I wanted it, I'd have to write it. And so, here we are, folks.
This reminds me of the apocryphal story about the mad professor. Crazy as a loon, the fellow was. At the sight of a book, any book -- at the library, at a bookstore, anywhere -- he would become totally obsessed with the idea that he could have written it, should have written it, and done a better job of it to boot. He would thereupon rush home and proceed to do just that, write a book with the very same title. When he died some years later, he allegedly had several thousand books to his credit, probably putting even Asimov to shame. The books might not have been any good, who knows, but does that really matter? Here's a fellow who lived his dream, even if he was obsessed by it, driven by it, and I can't help admiring the old coot...
Notes
[1] This is the notorious "flog it to death" technique.
Prev |
Home |
Next |
Endnotes |
Up |
About the Author |
http://tldp.org/LDP/abs/html/authorsnote.html [7/15/2002 6:34:42 PM]
About the Author
|
Advanced Bash-Scripting Guide: |
|
Prev |
Chapter 36. Endnotes |
Next |
36.2. About the Author
Who is this guy anyhow?
The author claims no credentials or special qualifications, other than a compulsion to write. [1] This book is somewhat of a departure from his other major work, HOW-2 Meet Women: The Shy Man's Guide to Relationships. He has also written the Software-Building HOWTO.
A Linux user since 1995 (Slackware 2.2, kernel 1.2.1), the author has emitted a few software truffles, including the cruft one-time pad encryption utility, the mcalc mortgage calculator, the judge Scrabble® adjudicator, and the yawl word gaming list package. He got his start in programming using FORTRAN IV on a CDC 3800, but is not the least bit nostalgic for those days.
Living in a secluded desert community with wife and dog, he cherishes human frailty.
Notes
[1] Those who can, do. Those who can't... get an MCSE.
Prev |
Home |
Next |
Author's Note |
Up |
Tools Used to Produce This |
|
|
Book |
http://tldp.org/LDP/abs/html/aboutauthor.html [7/15/2002 6:34:42 PM]
Tools Used to Produce This Book
|
Advanced Bash-Scripting Guide: |
|
Prev |
Chapter 36. Endnotes |
Next |
36.3. Tools Used to Produce This Book
36.3.1. Hardware
A used IBM Thinkpad, model 760XL laptop (P166, 104 meg RAM) running Red Hat 7.1/7.3. Sure, it's slow and has a funky keyboard, but it beats the heck out of a No. 2 pencil and a Big Chief tablet.
36.3.2. Software and Printware
i.Bram Moolenaar's powerful SGML-aware vim text editor.
ii.OpenJade, a DSSSL rendering engine for converting SGML documents into other formats.
iii.Norman Walsh's DSSSL stylesheets.
iv.DocBook, The Definitive Guide, by Norman Walsh and Leonard Muellner (O'Reilly, ISBN 1-56592-580-7). This is the standard reference for anyone attempting to write a document in Docbook SGML format.
Prev |
Home |
Next |
About the Author |
Up |
Credits |
http://tldp.org/LDP/abs/html/toolsused.html [7/15/2002 6:34:43 PM]
Credits
|
Advanced Bash-Scripting Guide: |
|
Prev |
Chapter 36. Endnotes |
Next |
36.4. Credits
Community participation made this project possible. The author gratefully acknowledges that writing this book would have been an impossible task without help and feedback from all you people out there.
Philippe Martin translated this document into DocBook/SGML. While not on the job at a small French company as a software developer, he enjoys working on GNU/Linux documentation and software, reading literature, playing music, and for his peace of mind making merry with friends. You may run across him somewhere in France or in the Basque Country, or email him at feloy@free.fr.
Philippe Martin also pointed out that positional parameters past $9 are possible using {bracket} notation, see Example 5-5.
Stephane Chazelas sent a long list of corrections, additions, and example scripts. More than a contributor, he has, in effect, taken on the role of editor for this document. Merci beaucoup!
I would like to especially thank Patrick Callahan, Mike Novak, and Pal Domokos for catching bugs, pointing out ambiguities, and for suggesting clarifications and changes. Their lively discussion of shell scripting and general documentation issues inspired me to try to make this document more readable.
I'm grateful to Jim Van Zandt for pointing out errors and omissions in version 0.2 of this document. He also contributed an instructive example script.
Many thanks to Jordi Sanfeliu for giving permission to use his fine tree script (Example A- 17).
Likewise, thanks to Michel Charpentier for permission to use his dc factoring script (Example 12-36).
http://tldp.org/LDP/abs/html/credits.html (1 of 3) [7/15/2002 6:34:43 PM]
Credits
Kudos to Noah Friedman for permission to use his string function script (Example A-18).
Emmanuel Rouat suggested corrections and additions on command substitution and aliases. He also contributed a very nice sample .bashrc file (Appendix G).
Heiner Steven kindly gave permission to use his base conversion script, Example 12-33. He also made a number of corrections and many helpful suggestions. Special thanks.
Rick Boivie contributed the delightfully recursive pb.sh script (Example 34-10) and suggested performance improvements for the monthlypmt.sh script (Example 12-32).
Florian Wisser enlightened me on some of the fine points of testing strings (see Example 7- 5), and on other matters.
Oleg Philon sent suggestions concerning cut and pidof.
Marc-Jano Knopp sent corrections on DOS batch files.
Hyun Jin Cha found several typos in the document in the process of doing a Korean translation. Thanks for pointing these out.
Andreas Abraham sent in a long list of typographical errors and other corrections. Special thanks!
Others making helpful suggestions and pointing out errors were Gabor Kiss, Leopold Toetsch, Peter Tillier, Marcus Berglof, Tony Richardson, Nick Drage (script ideas!), Rich Bartell, Jess Thrysoee, Adam Lazur, Bram Moolenaar, Baris Cicek, and David Lawyer (himself an author of 4 HOWTOs).
My gratitude to Chet Ramey and Brian Fox for writing Bash, an elegant and powerful scripting tool.
Very special thanks to the hard-working volunteers at the Linux Documentation Project. The LDP hosts a repository of Linux knowledge and lore, and has, to a large extent, enabled the publication of this book.
Thanks most of all to my wife, Anita, for her encouragement and emotional support.
http://tldp.org/LDP/abs/html/credits.html (2 of 3) [7/15/2002 6:34:43 PM]
Credits
Prev |
Home |
Next |
Tools Used to Produce This |
Up |
Bibliography |
Book |
|
|
http://tldp.org/LDP/abs/html/credits.html (3 of 3) [7/15/2002 6:34:43 PM]