You are previewing bash Cookbook.
O'Reilly logo
bash Cookbook

Book Description

The key to mastering any Unix system, especially Linux and Mac OS X, is a thorough knowledge of shell scripting. Scripting is a way to harness and customize the power of any Unix system, and it's an essential skill for any Unix users, including system administrators and professional OS X developers. But beneath this simple promise lies a treacherous ocean of variations in Unix commands and standards.

bash Cookbook teaches shell scripting the way Unix masters practice the craft. It presents a variety of recipes and tricks for all levels of shell programmers so that anyone can become a proficient user of the most common Unix shell -- the bash shell -- and cygwin or other popular Unix emulation packages. Packed full of useful scripts, along with examples that explain how to create better scripts, this new cookbook gives professionals and power users everything they need to automate routine tasks and enable them to truly manage their systems -- rather than have their systems manage them.

Table of Contents

  1. bash Cookbook
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Preface
      1. Who Should Read This Book
      2. About This Book
        1. GNU Software
        2. A Note About Code Examples
        3. Useless Use of cat
        4. A Note About Perl
        5. More Resources
      3. Conventions Used in This Book
      4. Using Code Examples
      5. We'd Like to Hear from You
      6. Safari® Enabled
      7. Acknowledgments
        1. Reviewers
        2. O'Reilly
        3. From the Authors
          1. Carl
          2. JP
          3. Cameron
    4. 1. Beginning bash
      1. 0. Why bash?
      2. 0. The bash Shell
      3. 1.1. Decoding the Prompt
        1. 1.1.1. Problem
        2. 1.1.2. Solution
        3. 1.1.3. Discussion
        4. 1.1.4. See Also
      4. 1.2. Showing Where You Are
        1. 1.2.1. Problem
        2. 1.2.2. Solution
        3. 1.2.3. Discussion
        4. 1.2.4. See Also
      5. 1.3. Finding and Running Commands
        1. 1.3.1. Problem
        2. 1.3.2. Solution
        3. 1.3.3. Discussion
        4. 1.3.4. See Also
      6. 1.4. Getting Information About Files
        1. 1.4.1. Problem
        2. 1.4.2. Solution
        3. 1.4.3. Discussion
        4. 1.4.4. See Also
      7. 1.5. Showing All Hidden (dot) Files in the Current Directory
        1. 1.5.1. Problem
        2. 1.5.2. Solution
        3. 1.5.3. Discussion
        4. 1.5.4. See Also
      8. 1.6. Using Shell Quoting
        1. 1.6.1. Problem
        2. 1.6.2. Solution
        3. 1.6.3. Discussion
        4. 1.6.4. See Also
      9. 1.7. Using or Replacing Built-ins and External Commands
        1. 1.7.1. Problem
        2. 1.7.2. Solution
        3. 1.7.3. Discussion
        4. 1.7.4. See Also
      10. 1.8. Determining If You Are Running Interactively
        1. 1.8.1. Problem
        2. 1.8.2. Solution
        3. 1.8.3. Discussion
        4. 1.8.4. See Also
      11. 1.9. Setting bash As Your Default Shell
        1. 1.9.1. Problem
        2. 1.9.2. Solution
        3. 1.9.3. Discussion
        4. 1.9.4. See Also
      12. 1.10. Getting bash for Linux
        1. 1.10.1. Problem
        2. 1.10.2. Solution
        3. 1.10.3. Discussion
        4. 1.10.4. See Also
      13. 1.11. Getting bash for xBSD
        1. 1.11.1. Problem
        2. 1.11.2. Solution
        3. 1.11.3. Discussion
        4. 1.11.4. See Also
      14. 1.12. Getting bash for Mac OS X
        1. 1.12.1. Problem
        2. 1.12.2. Solution
        3. 1.12.3. Discussion
        4. 1.12.4. See Also
      15. 1.13. Getting bash for Unix
        1. 1.13.1. Problem
        2. 1.13.2. Solution
        3. 1.13.3. Discussion
        4. 1.13.4. See Also
      16. 1.14. Getting bash for Windows
        1. 1.14.1. Problem
        2. 1.14.2. Solution
        3. 1.14.3. Discussion
        4. 1.14.4. See Also
      17. 1.15. Getting bash Without Getting bash
        1. 1.15.1. Problem
        2. 1.15.2. Solution
        3. 1.15.3. Discussion
        4. 1.15.4. See Also
      18. 1.16. Learning More About bash Documentation
        1. 1.16.1. Problem
        2. 1.16.2. Solution
          1. 1.16.2.1. Official documentation
          2. 1.16.2.2. Other documentation
        3. 1.16.3. See Also
    5. 2. Standard Output
      1. 2.1. Writing Output to the Terminal/Window
        1. 2.1.1. Problem
        2. 2.1.2. Solution
        3. 2.1.3. Discussion
        4. 2.1.4. See Also
      2. 2.2. Writing Output but Preserving Spacing
        1. 2.2.1. Problem
        2. 2.2.2. Solution
        3. 2.2.3. Discussion
        4. 2.2.4. See Also
      3. 2.3. Writing Output with More Formatting Control
        1. 2.3.1. Problem
        2. 2.3.2. Solution
        3. 2.3.3. Discussion
        4. 2.3.4. See Also
      4. 2.4. Writing Output Without the Newline
        1. 2.4.1. Problem
        2. 2.4.2. Solution
        3. 2.4.3. Discussion
        4. 2.4.4. See Also
      5. 2.5. Saving Output from a Command
        1. 2.5.1. Problem
        2. 2.5.2. Solution
        3. 2.5.3. Discussion
        4. 2.5.4. See Also
      6. 2.6. Saving Output to Other Files
        1. 2.6.1. Problem
        2. 2.6.2. Solution
        3. 2.6.3. Discussion
        4. 2.6.4. See Also
      7. 2.7. Saving Output from the ls Command
        1. 2.7.1. Problem
        2. 2.7.2. Solution
        3. 2.7.3. Discussion
        4. 2.7.4. See Also
      8. 2.8. Sending Both Output and Error Messages to Different Files
        1. 2.8.1. Problem
        2. 2.8.2. Solution
        3. 2.8.3. Discussion
        4. 2.8.4. See Also
      9. 2.9. Sending Both Output and Error Messages to the Same File
        1. 2.9.1. Problem
        2. 2.9.2. Solution
        3. 2.9.3. Discussion
        4. 2.9.4. See Also
      10. 2.10. Appending Rather Than Clobbering Output
        1. 2.10.1. Problem
        2. 2.10.2. Solution
        3. 2.10.3. Discussion
        4. 2.10.4. See Also
      11. 2.11. Using Just the Beginning or End of a File
        1. 2.11.1. Problem
        2. 2.11.2. Solution
        3. 2.11.3. Discussion
        4. 2.11.4. See Also
      12. 2.12. Skipping a Header in a File
        1. 2.12.1. Problem
        2. 2.12.2. Solution
        3. 2.12.3. Discussion
        4. 2.12.4. See Also
      13. 2.13. Throwing Output Away
        1. 2.13.1. Problem
        2. 2.13.2. Solution
        3. 2.13.3. Discussion
        4. 2.13.4. See Also
      14. 2.14. Saving or Grouping Output from Several Commands
        1. 2.14.1. Problem
        2. 2.14.2. Solution
        3. 2.14.3. Discussion
        4. 2.14.4. See Also
      15. 2.15. Connecting Two Programs by Using Output As Input
        1. 2.15.1. Problem
        2. 2.15.2. Solution
        3. 2.15.3. Discussion
        4. 2.15.4. See Also
      16. 2.16. Saving a Copy of Output Even While Using It As Input
        1. 2.16.1. Problem
        2. 2.16.2. Solution
        3. 2.16.3. Discussion
        4. 2.16.4. See Also
      17. 2.17. Connecting Two Programs by Using Output As Arguments
        1. 2.17.1. Problem
        2. 2.17.2. Solution
        3. 2.17.3. Discussion
        4. 2.17.4. See Also
      18. 2.18. Using Multiple Redirects on One Line
        1. 2.18.1. Problem
        2. 2.18.2. Solution
        3. 2.18.3. Discussion
        4. 2.18.4. See Also
      19. 2.19. Saving Output When Redirect Doesn't Seem to Work
        1. 2.19.1. Problem
        2. 2.19.2. Solution
        3. 2.19.3. Discussion
        4. 2.19.4. See Also
      20. 2.20. Swapping STDERR and STDOUT
        1. 2.20.1. Problem
        2. 2.20.2. Solution
        3. 2.20.3. Discussion
        4. 2.20.4. See Also
      21. 2.21. Keeping Files Safe from Accidental Overwriting
        1. 2.21.1. Problem
        2. 2.21.2. Solution
        3. 2.21.3. Discussion
        4. 2.21.4. See Also
      22. 2.22. Clobbering a File on Purpose
        1. 2.22.1. Problem
        2. 2.22.2. Solution
        3. 2.22.3. Discussion
        4. 2.22.4. See Also
    6. 3. Standard Input
      1. 3.1. Getting Input from a File
        1. 3.1.1. Problem
        2. 3.1.2. Solution
        3. 3.1.3. Discussion
        4. 3.1.4. See Also
      2. 3.2. Keeping Your Data with Your Script
        1. 3.2.1. Problem
        2. 3.2.2. Solution
        3. 3.2.3. Discussion
        4. 3.2.4. See Also
      3. 3.3. Preventing Weird Behavior in a Here-Document
        1. 3.3.1. Problem
        2. 3.3.2. Solution
        3. 3.3.3. Discussion
        4. 3.3.4. See Also
      4. 3.4. Indenting Here-Documents
        1. 3.4.1. Problem
        2. 3.4.2. Solution
        3. 3.4.3. Discussion
        4. 3.4.4. See Also
      5. 3.5. Getting User Input
        1. 3.5.1. Problem
        2. 3.5.2. Solution
        3. 3.5.3. Discussion
        4. 3.5.4. See Also
      6. 3.6. Getting Yes or No Input
        1. 3.6.1. Problem
        2. 3.6.2. Solution
        3. 3.6.3. Discussion
        4. 3.6.4. See Also
      7. 3.7. Selecting from a List of Options
        1. 3.7.1. Problem
        2. 3.7.2. Solution
        3. 3.7.3. Discussion
        4. 3.7.4. See Also
      8. 3.8. Prompting for a Password
        1. 3.8.1. Problem
        2. 3.8.2. Solution
        3. 3.8.3. Discussion
        4. 3.8.4. See Also
    7. 4. Executing Commands
      1. 4.1. Running Any Executable
        1. 4.1.1. Problem
        2. 4.1.2. Solution
        3. 4.1.3. Discussion
        4. 4.1.4. See Also
      2. 4.2. Telling If a Command Succeeded or Not
        1. 4.2.1. Problem
        2. 4.2.2. Solution
        3. 4.2.3. Discussion
        4. 4.2.4. See Also
      3. 4.3. Running Several Commands in Sequence
        1. 4.3.1. Problem
        2. 4.3.2. Solution
        3. 4.3.3. Discussion
      4. 4.4. Running Several Commands All at Once
        1. 4.4.1. Problem
        2. 4.4.2. Solution
        3. 4.4.3. Discussion
        4. 4.4.4. See Also
      5. 4.5. Deciding Whether a Command Succeeds
        1. 4.5.1. Problem
        2. 4.5.2. Solution
        3. 4.5.3. Discussion
        4. 4.5.4. See Also
      6. 4.6. Using Fewer if Statements
        1. 4.6.1. Problem
        2. 4.6.2. Solution
        3. 4.6.3. Discussion
        4. 4.6.4. See Also
      7. 4.7. Running Long Jobs Unattended
        1. 4.7.1. Problem
        2. 4.7.2. Solution
        3. 4.7.3. Discussion
        4. 4.7.4. See Also
      8. 4.8. Displaying Error Messages When Failures Occur
        1. 4.8.1. Problem
        2. 4.8.2. Solution
        3. 4.8.3. Discussion
        4. 4.8.4. See Also
      9. 4.9. Running Commands from a Variable
        1. 4.9.1. Problem
        2. 4.9.2. Solution
        3. 4.9.3. Discussion
        4. 4.9.4. See Also
      10. 4.10. Running All Scripts in a Directory
        1. 4.10.1. Problem
        2. 4.10.2. Solution
        3. 4.10.3. Discussion
        4. 4.10.4. See Also
    8. 5. Basic Scripting: Shell Variables
      1. 5.1. Documenting Your Script
        1. 5.1.1. Problem
        2. 5.1.2. Solution
        3. 5.1.3. Discussion
        4. 5.1.4. See Also
      2. 5.2. Embedding Documentation in Shell Scripts
        1. 5.2.1. Problem
        2. 5.2.2. Solution
        3. 5.2.3. Discussion
        4. 5.2.4. See Also
      3. 5.3. Promoting Script Readability
        1. 5.3.1. Problem
        2. 5.2.2. Solution
        3. 5.3.3. Discussion
        4. 5.3.4. See Also
      4. 5.4. Separating Variable Names from Surrounding Text
        1. 5.4.1. Problem
        2. 5.4.2. Solution
        3. 5.4.3. Discussion
        4. 5.4.4. See Also
      5. 5.5. Exporting Variables
        1. 5.5.1. Problem
        2. 5.5.2. Solution
        3. 5.5.3. Discussion
        4. 5.5.4. See Also
      6. 5.6. Seeing All Variable Values
        1. 5.6.1. Problem
        2. 5.6.2. Solution
        3. 5.6.3. Discussion
        4. 5.6.4. See Also
      7. 5.7. Using Parameters in a Shell Script
        1. 5.7.1. Problem
        2. 5.7.2. Solution
        3. 5.7.3. Discussion
        4. 5.7.4. See Also
      8. 5.8. Looping Over Arguments Passed to a Script
        1. 5.8.1. Problem
        2. 5.8.2. Solution
        3. 5.8.3. Discussion
        4. 5.8.4. See Also
      9. 5.9. Handling Parameters with Blanks
        1. 5.9.1. Problem
        2. 5.9.2. Solution
        3. 5.9.3. Discussion
        4. 5.9.4. See Also
      10. 5.10. Handling Lists of Parameters with Blanks
        1. 5.10.1. Problem
        2. 5.10.2. Solution
        3. 5.10.3. Discussion
        4. 5.10.4. See Also
      11. 5.11. Counting Arguments
        1. 5.11.1. Problem
        2. 5.11.2. Solution
        3. 5.11.3. Discussion
        4. 5.11.4. See Also
      12. 5.12. Consuming Arguments
        1. 5.12.1. Problem
        2. 5.12.2. Solution
        3. 5.12.3. Discussion
        4. 5.12.4. See Also
      13. 5.13. Getting Default Values
        1. 5.13.1. Problem
        2. 5.13.2. Solution
        3. 5.13.3. Discussion
        4. 5.13.4. See Also
      14. 5.14. Setting Default Values
        1. 5.14.1. Problem
        2. 5.14.2. Solution
        3. 5.14.3. Discussion
        4. 5.14.4. See Also
      15. 5.15. Using null As a Valid Default Value
        1. 5.15.1. Problem
        2. 5.15.2. Solution
        3. 5.15.3. Discussion
        4. 5.15.4. See Also
      16. 5.16. Using More Than Just a Constant String for Default
        1. 5.16.1. Problem
        2. 5.16.2. Solution
        3. 5.16.3. Discussion
        4. 5.16.4. See Also
      17. 5.17. Giving an Error Message for Unset Parameters
        1. 5.17.1. Problem
        2. 5.17.2. Solution
        3. 5.17.3. Discussion
        4. 5.17.4. See Also
      18. 5.18. Changing Pieces of a String
        1. 5.18.1. Problem
        2. 5.18.2. Solution
        3. 5.18.3. Discussion
        4. 5.18.4. See Also
      19. 5.19. Using Array Variables
        1. 5.19.1. Problem
        2. 5.19.2. Solution
        3. 5.19.3. Description
        4. 5.19.4. See Also
    9. 6. Shell Logic and Arithmetic
      1. 6.1. Doing Arithmetic in Your Shell Script
        1. 6.1.1. Problem
        2. 6.1.2. Solution
        3. 6.1.3. Discussion
        4. 6.1.4. See Also
      2. 6.2. Branching on Conditions
        1. 6.2.1. Problem
        2. 6.2.2. Solution
        3. 6.2.3. Discussion
        4. 6.2.4. See Also
      3. 6.3. Testing for File Characteristics
        1. 6.3.1. Problem
        2. 6.3.2. Solution
        3. 6.3.3. Discussion
        4. 6.3.4. See Also
      4. 6.4. Testing for More Than One Thing
        1. 6.4.1. Problem
        2. 6.4.2. Solution
        3. 6.4.3. Discussion
        4. 6.4.4. See Also
      5. 6.5. Testing for String Characteristics
        1. 6.5.1. Problem
        2. 6.5.2. Solution
        3. 6.5.3. Discussion
        4. 6.5.4. See Also
      6. 6.6. Testing for Equal
        1. 6.6.1. Problem
        2. 6.6.2. Solution
        3. 6.6.3. Discussion
        4. 6.6.4. See Also
      7. 6.7. Testing with Pattern Matches
        1. 6.7.1. Problem
        2. 6.7.2. Solution
        3. 6.7.3. Discussion
        4. 6.7.4. See Also
      8. 6.8. Testing with Regular Expressions
        1. 6.8.1. Problem
        2. 6.8.2. Solution
        3. 6.8.3. Discussion
        4. 6.8.4. See Also
      9. 6.9. Changing Behavior with Redirections
        1. 6.9.1. Problem
        2. 6.9.2. Solution
        3. 6.9.3. Discussion
        4. 6.9.4. See Also
      10. 6.10. Looping for a While
        1. 6.10.1. Problem
        2. 6.10.2. Solution
        3. 6.10.3. Discussion
        4. 6.10.4. See Also
      11. 6.11. Looping with a read
        1. 6.11.1. Problem
        2. 6.11.2. Solution
        3. 6.11.3. Discussion
        4. 6.11.4. See Also
      12. 6.12. Looping with a Count
        1. 6.12.1. Problem
        2. 6.12.2. Solution
        3. 6.12.3. Discussion
        4. 6.12.4. See Also
      13. 6.13. Looping with Floating-Point Values
        1. 6.13.1. Problem
        2. 6.13.2. Solution
        3. 6.13.3. Discussion
        4. 6.13.4. See Also
      14. 6.14. Branching Many Ways
        1. 6.14.1. Problem
        2. 6.14.2. Solution
        3. 6.14.3. Discussion
        4. 6.14.4. See Also
      15. 6.15. Parsing Command-Line Arguments
        1. 6.15.1. Problem
        2. 6.15.2. Solution
        3. 6.15.3. Discussion
        4. 6.15.4. See Also
      16. 6.16. Creating Simple Menus
        1. 6.16.1. Problem
        2. 6.16.2. Solution
        3. 6.16.3. Discussion
        4. 6.16.4. See Also
      17. 6.17. Changing the Prompt on Simple Menus
        1. 6.17.1. Problem
        2. 6.17.2. Solution
        3. 6.17.3. Discussion
        4. 6.17.4. See Also
      18. 6.18. Creating a Simple RPN Calculator
        1. 6.18.1. Problem
        2. 6.18.2. Solution
        3. 6.18.3. Discussion
        4. 6.18.4. See Also
      19. 6.19. Creating a Command-Line Calculator
        1. 6.19.1. Problem
        2. 6.19.2. Solution
        3. 6.19.3. Discussion
        4. 6.19.4. See Also
    10. 7. Intermediate Shell Tools I
      1. 7.1. Sifting Through Files for a String
        1. 7.1.1. Problem
        2. 7.1.2. Solution
        3. 7.1.3. Discussion
        4. 7.1.4. See Also
      2. 7.2. Getting Just the Filename from a Search
        1. 7.2.1. problem
        2. 7.2.2. Solution
        3. 7.2.3. Discussion
        4. 7.2.4. See Also
      3. 7.3. Getting a Simple True/False from a Search
        1. 7.3.1. problem
        2. 7.3.2. Solution
        3. 7.3.3. Discussion
        4. 7.3.4. See Also
      4. 7.4. Searching for Text While Ignoring Case
        1. 7.4.1. problem
        2. 7.4.2. Solution
        3. 7.4.3. Discussion
        4. 7.4.4. See Also
      5. 7.5. Doing a Search in a Pipeline
        1. 7.5.1. problem
        2. 7.5.2. Solution
        3. 7.5.3. Discussion
        4. 7.5.4. See Also
      6. 7.6. Paring Down What the Search Finds
        1. 7.6.1. problem
        2. 7.6.2. Solution
        3. 7.6.3. Discussion
        4. 7.6.4. See Also
      7. 7.7. Searching with More Complex Patterns
      8. 7.8. Searching for an SSN
        1. 7.8.1. problem
        2. 7.8.2. Solution
        3. 7.8.3. Discussion
        4. 7.8.4. See Also
      9. 7.9. Grepping Compressed Files
        1. 7.9.1. problem
        2. 7.9.2. Solution
        3. 7.9.3. Discussion
        4. 7.9.4. See Also
      10. 7.10. Keeping Some Output, Discarding the Rest
        1. 7.10.1. problem
        2. 7.10.2. Solution
        3. 7.10.3. Discussion
        4. 7.10.4. See Also
      11. 7.11. Keeping Only a Portion of a Line of Output
        1. 7.11.1. problem
        2. 7.11.2. Solution
        3. 7.11.3. Discussion
        4. 7.11.4. See Also
      12. 7.12. Reversing the Words on Each Line
        1. 7.12.1. problem
        2. 7.12.2. Solution
        3. 7.12.3. Discussion
        4. 7.12.4. See Also
      13. 7.13. Summing a List of Numbers
        1. 7.13.1. problem
        2. 7.13.2. Solution
        3. 7.13.3. Discussion
        4. 7.13.4. See Also
      14. 7.14. Counting String Values
        1. 7.14.1. problem
        2. 7.14.2. Solution
        3. 7.14.3. Discussion
        4. 7.14.4. See Also
      15. 7.15. Showing Data As a Quick and Easy Histogram
        1. 7.15.1. problem
        2. 7.15.2. Solution
        3. 7.15.3. Discussion
        4. 7.15.4. See Also
      16. 7.16. Showing a Paragraph of Text After a Found Phrase
        1. 7.16.1. Problem
        2. 7.16.2. Solution
        3. 7.16.3. Discussion
        4. 7.16.4. See Also
    11. 8. Intermediate Shell Tools II
      1. 8.1. Sorting Your Output
        1. 8.1.1. Problem
        2. 8.1.2. Solution
        3. 8.1.3. Discussion
        4. 8.1.4. See Also
      2. 8.2. Sorting Numbers
        1. 8.2.1. Problem
        2. 8.2.2. Solution
        3. 8.2.3. Discussion
        4. 8.2.4. See Also
      3. 8.3. Sorting IP Addresses
        1. 8.3.1. Problem
        2. 8.3.2. Solution
        3. 8.3.3. Discussion
        4. 8.3.4. See Also
      4. 8.4. Cutting Out Parts of Your Output
        1. 8.4.1. Problem
        2. 8.4.2. Solution
        3. 8.4.3. Discussion
        4. 8.4.4. See Also
      5. 8.5. Removing Duplicate Lines
        1. 8.5.1. Problem
        2. 8.5.2. Solution
        3. 8.5.3. Discussion
        4. 8.5.4. See Also
      6. 8.6. Compressing Files
        1. 8.6.1. Problem
        2. 8.6.2. Solution
        3. 8.6.3. Discussion
        4. 8.6.4. See Also
      7. 8.7. Uncompressing Files
        1. 8.7.1. Problem
        2. 8.7.2. Solution
        3. 8.7.3. Discussion
        4. 8.7.4. See Also
      8. 8.8. Checking a tar Archive for Unique Directories
        1. 8.8.1. Problem
        2. 8.8.2. Solution
        3. 8.8.3. Discussion
        4. 8.8.4. See Also
      9. 8.9. Translating Characters
        1. 8.9.1. Problem
        2. 8.9.2. Solution
        3. 8.9.3. Discussion
        4. 8.9.4. See Also
      10. 8.10. Converting Uppercase to Lowercase
        1. 8.10.1. Problem
        2. 8.10.2. Solution
        3. 8.10.3. Discussion
        4. 8.10.4. See Also
      11. 8.11. Converting DOS Files to Linux Format
        1. 8.11.1. Problem
        2. 8.11.2. Solution
        3. 8.11.3. Discussion
        4. 8.11.4. See Also
      12. 8.12. Removing Smart Quotes
        1. 8.12.1. Problem
        2. 8.12.2. Solution
        3. 8.12.3. Discussion
        4. 8.12.4. See Also
      13. 8.13. Counting Lines, Words, or Characters in a File
        1. 8.13.1. Problem
        2. 8.13.2. Solution
        3. 8.13.3. Discussion
        4. 8.13.4. See Also
      14. 8.14. Rewrapping Paragraphs
        1. 8.14.1. Problem
        2. 8.14.2. Solution
        3. 8.14.3. Discussion
        4. 8.14.4. See Also
      15. 8.15. Doing More with less
        1. 8.15.1. Problem
        2. 8.15.2. Solution
        3. 8.15.3. Discussion
        4. 8.15.4. See Also
    12. 9. Finding Files: find, locate, slocate
      1. 9.1. Finding All Your MP3 Files
        1. 9.1.1. Problem
        2. 9.1.2. Solution
        3. 9.1.3. Discussion
        4. 9.1.4. See Also
      2. 9.2. Handling Filenames Containing Odd Characters
        1. 9.2.1. Problem
        2. 9.2.2. Solution
        3. 9.2.3. Discussion
        4. 9.2.4. See Also
      3. 9.3. Speeding Up Operations on Found Files
        1. 9.3.1. Problem
        2. 9.3.2. Solution
        3. 9.3.3. See Also
      4. 9.4. Finding Files Across Symbolic Links
        1. 9.4.1. Problem
        2. 9.4.2. Solution
        3. 9.4.3. Discussion
        4. 9.4.4. See Also
      5. 9.5. Finding Files Irrespective of Case
        1. 9.5.1. Problem
        2. 9.5.2. Solution
        3. 9.5.3. Discussion
        4. 9.5.4. See Also
      6. 9.6. Finding Files by Date
        1. 9.6.1. Problem
        2. 9.6.2. Solution
        3. 9.6.3. Discussion
        4. 9.6.4. See Also
      7. 9.7. Finding Files by Type
        1. 9.7.1. Problem
        2. 9.7.2. Solution
        3. 9.7.3. Discussion
        4. 9.7.4. See Also
      8. 9.8. Finding Files by Size
        1. 9.8.1. Problem
        2. 9.8.2. Solution
        3. 9.8.3. Discussion
        4. 9.8.4. See Also
      9. 9.9. Finding Files by Content
        1. 9.9.1. Problem
        2. 9.9.2. Solution
        3. 9.9.3. Discussion
        4. 9.9.4. See Also
      10. 9.10. Finding Existing Files and Content Fast
        1. 9.10.1. Problem
        2. 9.10.2. Solution
        3. 9.10.3. Discussion
        4. 9.10.4. See Also
      11. 9.11. Finding a File Using a List of Possible Locations
        1. 9.11.1. Problem
        2. 9.11.2. Solution
        3. 9.11.3. Discussion
        4. 9.11.4. See Also
    13. 10. Additional Features for Scripting
      1. 10.1. "Daemon-izing" Your Script
        1. 10.1.1. Problem
        2. 10.1.2. Solution
        3. 10.1.3. Discussion
        4. 10.1.4. See Also
      2. 10.2. Reusing Code with Includes and Sourcing
        1. 10.2.1. Problem
        2. 10.2.2. Solution
        3. 10.2.3. Discussion
        4. 10.2.4. See Also
      3. 10.3. Using Configuration Files in a Script
        1. 10.3.1. Problem
        2. 10.3.2. Solution
        3. 10.3.3. Discussion
        4. 10.3.4. See Also
      4. 10.4. Defining Functions
        1. 10.4.1. Problem
        2. 10.4.2. Solution
        3. 10.4.3. Discussion
        4. 10.4.4. See Also
      5. 10.5. Using Functions: Parameters and Return Values
        1. 10.5.1. Problem
        2. 10.5.2. Solution
        3. 10.5.3. Discussion
        4. 10.5.4. See Also
      6. 10.6. Trapping Interrupts
        1. 10.6.1. Problem
        2. 10.6.2. Solution
        3. 10.6.3. Discussion
        4. 10.6.4. See Also
      7. 10.7. Redefining Commands with alias
        1. 10.7.1. Problem
        2. 10.7.2. Solution
        3. 10.7.3. Discussion
        4. 10.7.4. See Also
      8. 10.8. Avoiding Aliases, Functions
        1. 10.8.1. Problem
        2. 10.8.2. Solution
        3. 10.8.3. Discussion
        4. 10.8.4. See Also
    14. 11. Working with Dates and Times
      1. 11.1. Formatting Dates for Display
        1. 11.1.1. Problem
        2. 11.1.2. Solution
        3. 11.1.3. Discussion
        4. 11.1.4. See Also
      2. 11.2. Supplying a Default Date
        1. 11.2.1. Problem
        2. 11.2.2. Solution
        3. 11.2.3. Discussion
        4. 11.2.4. See Also
      3. 11.3. Automating Date Ranges
        1. 11.3.1. Problem
        2. 11.3.2. Solution
        3. 11.3.3. Discussion
        4. 11.3.4. See Also
      4. 11.4. Converting Dates and Times to Epoch Seconds
        1. 11.4.1. Problem
        2. 11.4.2. Solution
        3. 11.4.3. Discussion
        4. 11.4.4. See Also
      5. 11.5. Converting Epoch Seconds to Dates and Times
        1. 11.5.1. Problem
        2. 11.5.2. Solution
        3. 11.5.3. Discussion
        4. 11.5.4. See Also
      6. 11.6. Getting Yesterday or Tomorrow with Perl
        1. 11.6.1. Problem
        2. 11.6.2. Solution
        3. 11.6.3. Discussion
        4. 11.6.4. See Also
      7. 11.7. Figuring Out Date and Time Arithmetic
        1. 11.7.1. Problem
        2. 11.7.2. Solution
        3. 11.7.3. Discussion
        4. 11.7.4. See Also
      8. 11.8. Handling Time Zones, Daylight Saving Time, and Leap Years
        1. 11.8.1. Problem
        2. 11.8.2. Solution
        3. 11.8.3. See Also
      9. 11.9. Using date and cron to Run a Script on the Nth Day
        1. 11.9.1. Problem
        2. 11.9.2. Solution
        3. 11.9.3. Discussion
        4. 11.9.4. See Also
    15. 12. End-User Tasks As Shell Scripts
      1. 12.1. Starting Simple by Printing Dashes
        1. 12.1.1. Problem
        2. 12.1.2. Solution
        3. 12.1.3. Discussion
        4. 12.1.4. See Also
      2. 12.2. Viewing Photos in an Album
        1. 12.2.1. Problem
        2. 12.2.2. Solution
        3. 12.2.3. Discussion
        4. 12.2.4. See Also
      3. 12.3. Loading Your MP3 Player
        1. 12.3.1. Problem
        2. 12.3.2. Solution
        3. 12.3.3. Discussion
        4. 12.3.4. See Also
      4. 12.4. Burning a CD
        1. 12.4.1. Problem
        2. 12.4.2. Solution
        3. 12.4.3. Discussion
        4. 12.4.4. See Also
      5. 12.5. Comparing Two Documents
        1. 12.5.1. Problem
        2. 12.5.2. Solution
        3. 12.5.3. Discussion
        4. 12.5.4. See Also
    16. 13. Parsing and Similar Tasks
      1. 13.1. Parsing Arguments for Your Shell Script
        1. 13.1.1. Problem
        2. 13.1.2. Solution
        3. 13.1.3. Discussion
        4. 13.1.4. See Also
      2. 13.2. Parsing Arguments with Your Own Error Messages
        1. 13.2.1. Problem
        2. 13.2.2. Solution
        3. 13.2.3. Discussion
        4. 13.2.4. See Also
      3. 13.3. Parsing Some HTML
        1. 13.3.1. Problem
        2. 13.3.2. Solution
        3. 13.3.3. Discussion
        4. 13.3.4. See Also
      4. 13.4. Parsing Output into an Array
        1. 13.4.1. Problem
        2. 13.4.2. Solution
        3. 13.4.3. Discussion
        4. 13.4.4. See Also
      5. 13.5. Parsing Output with a Function Call
        1. 13.5.1. Problem
        2. 13.5.2. Solution
        3. 13.5.3. Discussion
        4. 13.5.4. See Also
      6. 13.6. Parsing Text with a read Statement
        1. 13.6.1. Problem
        2. 13.6.2. Solution
        3. 13.6.3. Discussion
        4. 13.6.4. See Also
      7. 13.7. Parsing with read into an Array
        1. 13.7.1. Problem
        2. 13.7.2. Solution
        3. 13.7.3. Discussion
        4. 13.7.4. See Also
      8. 13.8. Getting Your Plurals Right
        1. 13.8.1. Problem
        2. 13.8.2. Solution
        3. 13.8.3. Discussion
        4. 13.8.4. See Also
      9. 13.9. Taking It One Character at a Time
        1. 13.9.1. Problem
        2. 13.9.2. Solution
        3. 13.9.3. Discussion
        4. 13.9.4. See Also
      10. 13.10. Cleaning Up an SVN Source Tree
        1. 13.10.1. Problem
        2. 13.10.2. Solution
        3. 13.10.3. Discussion
        4. 13.10.4. See Also
      11. 13.11. Setting Up a Database with MySQL
        1. 13.11.1. Problem
        2. 13.11.2. Solution
        3. 13.11.3. Discussion
        4. 13.11.4. See Also
      12. 13.12. Isolating Specific Fields in Data
        1. 13.12.1. Problem
        2. 13.12.2. Solution
        3. 13.12.3. Discussion
        4. 13.12.4. See Also
      13. 13.13. Updating Specific Fields in Data Files
        1. 13.13.1. Problem
        2. 13.13.2. Solution
        3. 13.3. Discussion
        4. 13.13.4. See Also
      14. 13.14. Trimming Whitespace
        1. 13.14.1. Problem
        2. 13.14.2. Solution
        3. 13.14.3. Discussion
        4. 13.14.4. See Also
      15. 13.15. Compressing Whitespace
        1. 13.15.1. Problem
        2. 13.15.2. Solution
        3. 13.15.3. Discussion
        4. 13.15.4. See Also
      16. 13.16. Processing Fixed-Length Records
        1. 13.16.1. Problem
        2. 13.16.2. Solution
        3. 13.16.3. Discussion
        4. 13.16.4. See Also
      17. 13.17. Processing Files with No Line Breaks
        1. 13.17.1. Problem
        2. 13.17.2. Solution
        3. 13.17.3. Discussion
        4. 13.17.4. See Also
      18. 13.18. Converting a Data File to CSV
        1. 13.18.1. Problem
        2. 13.18.2. Solution
        3. 13.18.3. Discussion
        4. 13.18.4. See Also
      19. 13.19. Parsing a CSV Data File
        1. 13.19.1. Problem
        2. 13.19.2. Solution
        3. 13.19.3. Discussion
        4. 13.19.4. See Also
    17. 14. Writing Secure Shell Scripts
      1. 14.1. Avoiding Common Security Problems
        1. 14.1.1. Problem
        2. 14.1.2. Solution
        3. 14.1.3. Discussion
        4. 14.1.4. See Also
      2. 14.2. Avoiding Interpreter Spoofing
        1. 14.2.1. Problem
        2. 14.2.2. Solution
        3. 14.2.3. Discussion
        4. 14.2.4. See Also
      3. 14.3. Setting a Secure $PATH
        1. 14.3.1. Problem
        2. 14.3.2. Solution
        3. 14.3.3. Discussion
        4. 14.3.4. See Also
      4. 14.4. Clearing All Aliases
        1. 14.4.1. Problem
        2. 14.4.2. Solution
        3. 14.4.3. Discussion
        4. 14.4.4. See Also
      5. 14.5. Clearing the Command Hash
        1. 14.5.1. Problem
        2. 14.5.2. Solution
        3. 14.5.3. Discussion
        4. 14.5.4. See Also
      6. 14.6. Preventing Core Dumps
        1. 14.6.1. Problem
        2. 14.6.2. Solution
        3. 14.6.3. Discussion
        4. 14.6.4. See Also
      7. 14.7. Setting a Secure $IFS
        1. 14.7.1. Problem
        2. 14.7.2. Solution
        3. 14.7.3. Discussion
        4. 14.7.4. See Also
      8. 14.8. Setting a Secure umask
        1. 14.8.1. Problem
        2. 14.8.2. Solution
        3. 14.8.3. Discussion
        4. 14.8.4. See Also
      9. 14.9. Finding World-Writable Directories in Your $PATH
        1. 14.9.1. Problem
        2. 14.9.2. Solution
        3. 14.9.3. Discussion
        4. 14.9.4. See Also
      10. 14.10. Adding the Current Directory to the $PATH
        1. 14.10.1. Problem
        2. 14.10.2. Solution
        3. 14.10.3. Discussion
        4. 14.10.4. See Also
      11. 14.11. Using Secure Temporary Files
        1. 14.11.1. Problem
        2. 14.11.2. Solution
        3. 14.11.3. Discussion
        4. 14.11.4. See Also
      12. 14.12. Validating Input
        1. 14.12.1. Problem
        2. 14.12.2. Solution
        3. 14.12.3. Discussion
        4. 14.12.4. See Also
      13. 14.13. Setting Permissions
        1. 14.13.1. Problem
        2. 14.13.2. Solution
        3. 14.13.3. Discussion
        4. 14.13.4. See Also
      14. 14.14. Leaking Passwords into the Process List
        1. 14.14.1. Problem
        2. 14.14.2. Solution
        3. 14.14.3. Discussion
        4. 14.14.4. See Also
      15. 14.15. Writing setuid or setgid Scripts
        1. 14.15.1. Problem
        2. 14.15.2. Solution
        3. 14.15.3. Discussion
        4. 14.15.4. See Also
      16. 14.16. Restricting Guest Users
        1. 14.16.1. Problem
        2. 14.16.2. Solution
        3. 14.16.3. Discussion
        4. 14.16.4. See Also
      17. 14.17. Using chroot Jails
        1. 14.17.1. Problem
        2. 14.17.2. Solution
        3. 14.17.3. Discussion
        4. 14.17.4. See Also
      18. 14.18. Running As a Non-root User
        1. 14.18.1. Problem
        2. 14.18.2. Solution
        3. 14.18.3. Discussion
        4. 14.18.4. See Also
      19. 14.19. Using sudo More Securely
        1. 14.19.1. Problem
        2. 14.19.2. Solution
        3. 14.19.3. Discussion
        4. 14.19.4. See Also
      20. 14.20. Using Passwords in Scripts
        1. 14.20.1. Problem
        2. 14.20.2. Solution
        3. 14.20.3. Discussion
        4. 14.20.4. See Also
      21. 14.21. Using SSH Without a Password
        1. 14.21.1. Problem
        2. 14.21.2. Solution
        3. 14.21.3. Discussion
        4. 14.21.4. See Also
      22. 14.22. Restricting SSH Commands
        1. 14.22.1. Problem
        2. 14.22.2. Solution
        3. 14.22.3. Discussion
        4. 14.22.4. See Also
      23. 14.23. Disconnecting Inactive Sessions
        1. 14.23.1. Problem
        2. 14.23.2. Solution
        3. 14.23.3. Discussion
        4. 14.23.4. See Also
    18. 15. Advanced Scripting
      1. 15.1. Finding bash Portably for #!
        1. 15.1.1. Problem
        2. 15.1.2. Solution
        3. 15.1.3. Discussion
        4. 15.1.4. See Also
      2. 15.2. Setting a POSIX $PATH
        1. 15.2.1. Problem
        2. 15.2.2. Solution
        3. 15.2.3. Discussion
        4. 15.2.4. See Also
      3. 15.3. Developing Portable Shell Scripts
        1. 15.3.1. Problem
        2. 15.3.2. Solution
        3. 15.3.3. Discussion
        4. 15.3.4. See Also
      4. 15.4. Testing Scripts in VMware
        1. 15.4.1. Problem
        2. 15.4.2. Solution
        3. 15.4.3. Discussion
        4. 15.4.4. See Also
      5. 15.5. Using for Loops Portably
        1. 15.5.1. Problem
        2. 15.5.2. Solution
        3. 15.5.3. Discussion
        4. 15.5.4. See Also
      6. 15.6. Using echo Portably
        1. 15.6.1. Problem
        2. 15.6.2. Solution
        3. 15.6.3. Discussion
        4. 15.6.4. See Also
      7. 15.7. Splitting Output Only When Necessary
        1. 15.7.1. Problem
        2. 15.7.2. Solution
        3. 15.7.3. Discussion
        4. 15.7.4. See Also
      8. 15.8. Viewing Output in Hex
        1. 15.8.1. Problem
        2. 15.8.2. Solution
        3. 15.8.3. Discussion
        4. 15.8.4. See Also
      9. 15.9. Using bash Net-Redirection
        1. 15.9.1. Problem
        2. 15.9.2. Solution
        3. 15.9.3. Discussion
        4. 15.9.4. See Also
      10. 15.10. Finding My IP Address
        1. 15.10.1. Problem
        2. 15.10.2. Solution
        3. 15.10.3. Discussion
        4. 15.10.4. See Also
      11. 15.11. Getting Input from Another Machine
        1. 15.11.1. Problem
        2. 15.11.2. Solution
        3. 15.11.3. Discussion
        4. 15.11.4. See Also
      12. 15.12. Redirecting Output for the Life of a Script
        1. 15.12.1. Problem
        2. 15.12.2. Solution
        3. 15.12.3. Discussion
        4. 15.12.4. See Also
      13. 15.13. Working Around "argument list too long" Errors
        1. 15.13.1. Problem
        2. 15.13.2. Solution
        3. 15.13.3. Discussion
        4. 15.13.4. See Also
      14. 15.14. Logging to syslog from Your Script
        1. 15.14.1. Problem
        2. 15.14.2. Solution
        3. 15.14.3. Discussion
        4. 15.14.4. See Also
      15. 15.15. Sending Email from Your Script
        1. 15.15.1. Problem
        2. 15.15.2. Solution
        3. 15.15.3. Discussion
        4. 15.15.4. See Also
      16. 15.16. Automating a Process Using Phases
        1. 15.16.1. Problem
        2. 15.16.2. Solution
        3. 15.16.3. Discussion
        4. 15.16.4. See Also
    19. 16. Configuring and Customizing bash
      1. 16.1. bash Startup Options
        1. 16.1.1. Problem
        2. 16.1.2. Solution
        3. 16.1.3. Discussion
        4. 16.1.4. See Also
      2. 16.2. Customizing Your Prompt
        1. 16.2.1. Problem
        2. 16.2.2. Solution
          1. 16.2.2.1. Basic prompts
          2. 16.2.2.2. Fancy prompts
        3. 16.2.3. Discussion
          1. 16.2.3.1. Colors
        4. 16.2.4. See Also
      3. 16.3. Change Your $PATH Permanently
        1. 16.3.1. Problem
        2. 16.3.2. Solution
        3. 16.3.3. Discussion
        4. 16.3.4. See Also
      4. 16.4. Change Your $PATH Temporarily
        1. 16.4.1. Problem
        2. 16.4.2. Solution
        3. 16.4.3. Discussion
        4. 16.4.4. See Also
      5. 16.5. Setting Your $CDPATH
        1. 16.5.1. Problem
        2. 16.5.2. Solution
        3. 16.5.3. Discussion
        4. 16.5.4. See Also
      6. 16.6. Shortening or Changing Command Names
        1. 16.6.1. Problem
        2. 16.6.2. Solution
        3. 16.6.3. Discussion
        4. 16.6.4. See Also
      7. 16.7. Adjusting Shell Behavior and Environment
        1. 16.7.1. Problem
        2. 16.7.2. Solution
        3. 16.7.3. Discussion
        4. 16.7.4. See Also
      8. 16.8. Adjusting readline Behavior Using .inputrc
        1. 16.8.1. Problem
        2. 16.8.2. Solution
        3. 16.8.3. Discussion
        4. 16.8.4. See Also
      9. 16.9. Keeping a Private Stash of Utilities by Adding ~/bin
        1. 16.9.1. Problem
        2. 16.9.2. Solution
        3. 16.9.3. Discussion
        4. 16.9.4. See Also
      10. 16.10. Using Secondary Prompts: $PS2, $PS3, $PS4
        1. 16.10.1. Problem
        2. 16.10.2. Solution
        3. 16.10.3. Discussion
        4. 16.10.4. See Also
      11. 16.11. Synchronizing Shell History Between Sessions
        1. 16.11.1. Problem
        2. 16.11.2. Solution
        3. 16.11.3. Discussion
        4. 16.11.4. See Also
      12. 16.12. Setting Shell History Options
        1. 16.12.1. Problem
        2. 16.12.2. Solution
        3. 16.12.3. Discussion
        4. 16.12.4. See Also
      13. 13. Creating a Better cd Command
        1. 16.13.1. Problem
        2. 16.13.2. Solution
        3. 16.13.3. Discussion
        4. 16.13.4. See Also
      14. 16.14. Creating and Changing into a New Directory in One Step
        1. 16.14.1. Problem
        2. 16.14.2. Solution
        3. 16.14.3. Discussion
        4. 16.14.4. See Also
      15. 16.15. Getting to the Bottom of Things
        1. 16.15.1. Problem
        2. 16.15.2. Solution
        3. 16.15.3. Discussion
        4. 16.15.4. See Also
      16. 16.16. Adding New Features to bash Using Loadable Built-ins
        1. 16.16.1. Problem
        2. 16.16.2. Solution
        3. 16.16.3. Discussion
        4. 16.16.4. See Also
      17. 16.17. Improving Programmable Completion
        1. 16.17.1. Problem
        2. 16.17.2. Solution
        3. 16.17.3. Discussion
        4. 16.17.4. See Also
      18. 16.18. Using Initialization Files Correctly
        1. 16.18.1. Problem
        2. 16.18.2. Solution
        3. 16.18.3. Discussion
        4. 16.18.4. See Also
      19. 16.19. Creating Self-Contained, Portable RC Files
        1. 16.19.1. Problem
        2. 16.19.2. Solution
        3. 16.19.3. Discussion
          1. 16.19.3.1. Assumptions
          2. 16.19.3.2. Criteria
        4. 16.19.4. See Also
      20. 16.20. Getting Started with a Custom Configuration
        1. 16.20.1. Problem
        2. 16.20.2. Solution
        3. 16.20.3. Discussion
        4. 16.20.4. See Also
    20. 17. Housekeeping and Administrative Tasks
      1. 17.1. Renaming Many Files
        1. 17.1.1. Problem
        2. 17.1.2. Solution
        3. 17.1.3. Discussion
        4. 17.1.4. See Also
      2. 17.2. Using GNU Texinfo and Info on Linux
        1. 17.2.1. Problem
        2. 17.2.2. Solution
        3. 17.2.3. Discussion
        4. 17.2.4. See Also
      3. 17.3. Unzipping Many ZIP Files
        1. 17.3.1. Problem
        2. 17.3.2. Solution
        3. 17.3.3. Discussion
        4. 17.3.4. See Also
      4. 17.4. Recovering Disconnected Sessions Using screen
        1. 17.4.1. Problem
        2. 17.4.2. Solution
        3. 17.4.3. Discussion
          1. 17.4.3.1. Caveats
          2. 17.4.3.2. Configuration
        4. 17.4.4. See Also
      5. 17.5. Sharing a Single bash Session
        1. 17.5.1. Problem
        2. 17.5.2. Solution
        3. 17.5.3. Discussion
        4. 17.5.4. See Also
      6. 17.6. Logging an Entire Session or Batch Job
        1. 17.6.1. Problem
        2. 17.6.2. Solution
        3. 17.6.3. Discussion
        4. 17.6.4. See Also
      7. 17.7. Clearing the Screen When You Log Out
        1. 17.7.1. Problem
        2. 17.7.2. Solution
        3. 17.7.3. Discussion
        4. 17.7.4. See Also
      8. 17.8. Capturing File Metadata for Recovery
        1. 17.8.1. Problem
        2. 17.8.2. Solution
        3. 17.8.3. Discussion
        4. 17.8.4. See Also
      9. 17.9. Creating an Index of Many Files
        1. 17.9.1. Problem
        2. 17.9.2. Solution
        3. 17.9.3. Discussion
        4. 17.9.4. See Also
      10. 17.10. Using diff and patch
        1. 17.10.1. Problem
        2. 17.10.2. Solution
        3. 17.10.3. Discussion
        4. 17.10.4. See Also
      11. 17.11. Counting Differences in Files
        1. 17.11.1. Problem
        2. 17.11.2. Solution
        3. 17.11.3. Discussion
        4. 17.11.4. See Also
      12. 17.12. Removing or Renaming Files Named with Special Characters
        1. 17.12.1. Problem
        2. 17.12.2. Solution
        3. 17.12.3. Discussion
        4. 17.12.4. See Also
      13. 17.13. Prepending Data to a File
        1. 17.13.1. Problem
        2. 17.13.2. Solution
        3. 17.13.3. Discussion
        4. 17.13.4. See Also
      14. 17.14. Editing a File in Place
        1. 17.14.1. Problem
        2. 17.14.2. Solution
        3. 17.14.3. Discussion
        4. 17.14.4. See Also
      15. 17.15. Using sudo on a Group of Commands
        1. 17.15.1. Problem
        2. 17.15.2. Solution
        3. 17.15.3. Discussion
        4. 17.15.4. See Also
      16. 17.16. Finding Lines in One File But Not in the Other
        1. 17.16.1. Problem
        2. 17.16.2. Solution
        3. 17.16.3. Discussion
        4. 17.16.4. See Also
      17. 17.17. Keeping the Most Recent N Objects
        1. 17.17.1. Problem
        2. 17.17.2. Solution
        3. 17.17.3. Discussion
        4. 17.17.4. See Also
      18. 17.18. Grepping ps Output Without Also Getting the grep Process Itself
        1. 17.18.1. Problem
        2. 17.18.2. Solution
        3. 17.18.3. Discussion
        4. 17.18.4. See Also
      19. 17.19. Finding Out Whether a Process Is Running
        1. 17.19.1. Problem
        2. 17.19.2. Solution
        3. 17.19.3. Discussion
        4. 17.19.4. See Also
      20. 17.20. Adding a Prefix or Suffix to Output
        1. 17.20.1. Problem
        2. 17.20.2. Solution
        3. 17.20.3. Discussion
        4. 17.20.4. See Also
      21. 17.21. Numbering Lines
        1. 17.21.1. Problem
        2. 17.21.2. Solution
        3. 17.21.3. Discussion
        4. 17.21.4. See Also
      22. 17.22. Writing Sequences
        1. 17.22.1. Problem
        2. 17.22.2. Solution
        3. 17.22.3. Discussion
        4. 17.22.4. See Also
      23. 17.23. Emulating the DOS Pause Command
        1. 17.23.1. Problem
        2. 17.23.2. Solution
        3. 17.23.3. Discussion
        4. 17.23.4. See Also
      24. 17.24. Commifying Numbers
        1. 17.24.1. Problem
        2. 17.24.2. Solution
        3. 17.24.3. Discussion
        4. 17.24.4. See Also
    21. 18. Working Faster by Typing Less
      1. 18.1. Moving Quickly Among Arbitrary Directories
        1. 18.1.1. Problem
        2. 18.1.2. Solution
        3. 18.1.3. Discussion
        4. 18.1.4. See Also
      2. 18.2. Repeating the Last Command
        1. 18.2.1. Problem
        2. 18.2.2. Solution
        3. 18.2.3. Description
        4. 18.2.4. See Also
      3. 18.3. Running Almost the Same Command
        1. 18.3.1. Problem
        2. 18.3.2. Solution
        3. 18.3.3. Discussion
        4. 18.3.4. See Also
      4. 18.4. Substituting Across Word Boundaries
        1. 18.4.1. Problem
        2. 18.4.2. Solution
        3. 18.4.3. Discussion
        4. 18.4.4. See Also
      5. 18.5. Reusing Arguments
        1. 18.5.1. Problem
        2. 18.5.2. Solution
        3. 18.5.3. Discussion
        4. 18.5.4. See Also
      6. 18.6. Finishing Names for You
        1. 18.6.1. Problem
        2. 18.6.2. Solution
        3. 18.6.3. Discussion
        4. 18.6.4. See Also
      7. 18.7. Playing It Safe
        1. 18.7.1. Problem
        2. 18.7.2. Solution
        3. 18.7.3. Discussion
        4. 18.7.4. See Also
    22. 19. Tips and Traps: Common Goofs for Novices
      1. 19.1. Forgetting to Set Execute Permissions
        1. 19.1.1. Problem
        2. 19.1.2. Solution
        3. 19.1.3. Discussion
        4. 19.1.4. See Also
      2. 19.2. Fixing "No such file or directory" Errors
        1. 19.2.1. Problem
        2. 19.2.2. Solution
        3. 19.2.3. Discussion
        4. 19.2.4. See Also
      3. 19.3. Forgetting That the Current Directory Is Not in the $PATH
        1. 19.3.1. Problem
        2. 19.3.2. Solution
        3. 19.3.3. Discussion
        4. 19.3.4. See Also
      4. 19.4. Naming Your Script Test
        1. 19.4.1. Problem
        2. 19.4.2. Solution
        3. 19.4.3. Discussion
        4. 19.4.4. See Also
      5. 19.5. Expecting to Change Exported Variables
        1. 19.5.1. Problem
        2. 19.5.2. Solution
        3. 19.5.3. Discussion
        4. 19.5.4. See Also
      6. 19.6. Forgetting Quotes Leads to "command not found" on Assignments
        1. 19.6.1. Problem
        2. 19.6.2. Solution
        3. 19.6.3. Discussion
        4. 19.6.4. See Also
      7. 19.7. Forgetting That Pattern Matching Alphabetizes
      8. 19.8. Forgetting That Pipelines Make Subshells
        1. 19.8.1. Problem
        2. 19.8.2. Solution
        3. 19.8.3. Discussion
        4. 19.8.4. See Also
      9. 19.9. Making Your Terminal Sane Again
        1. 19.9.1. Problem
        2. 19.9.2. Solution
        3. 19.9.3. Discussion
        4. 19.9.4. See Also
      10. 19.10. Deleting Files Using an Empty Variable
        1. 19.10.1. Problem
        2. 19.10.2. Solution
        3. 19.10.3. Discussion
        4. 19.10.4. See Also
      11. 19.11. Seeing Odd Behavior from printf
        1. 19.11.1. Problem
        2. 19.11.2. Solution
        3. 19.11.3. Discussion
        4. 19.11.4. See Also
      12. 19.12. Testing bash Script Syntax
        1. 19.12.1. Problem
        2. 19.12.2. Solution
        3. 19.12.3. Discussion
        4. 19.12.4. See Also
      13. 19.13. Debugging Scripts
        1. 19.13.1. Problem
        2. 19.13.2. Solution
        3. 19.13.3. Discussion
        4. 19.13.4. See Also
      14. 19.14. Avoiding "command not found" When Using Functions
        1. 19.14.1. Problem
        2. 19.14.2. Solution
        3. 19.14.3. Discussion
        4. 19.14.4. See Also
      15. 19.15. Confusing Shell Wildcards and Regular Expressions
        1. 19.15.1. Problem
        2. 19.15.2. Solution
        3. 19.15.3. Discussion
        4. 19.15.4. See Also
    23. A. Reference Lists
      1. A.1. bash Invocation
      2. A.2. Prompt String Customizations
      3. A.3. ANSI Color Escape Sequences
      4. A.4. Built-in Commands and Reserved Words
      5. A.5. Built-in Shell Variables
      6. A.6. set Options
      7. A.7. shopt options
      8. A.8. Adjusting Shell Behavior Using set, shopt, and Environment Variables
      9. A.9. Test Operators
      10. A.10. I/O Redirection
      11. A.11. echo Options and Escape Sequences
      12. A.12. printf
        1. A.12.1. Examples
        2. A.12.2. See Also
      13. A.13. Date and Time String Formatting with strftime
      14. A.14. Pattern-Matching Characters
      15. A.15. extglob Extended Pattern-Matching Operators
      16. A.16. tr Escape Sequences
      17. A.17. Readline Init File Syntax
      18. A.18. emacs Mode Commands
      19. A.19. vi Control Mode Commands
      20. A.20. Table of ASCII Values
    24. B. Examples Included with bash
      1. B.1. Startup-Files Directory Examples
    25. C. Command-Line Processing
      1. C.1. Command-Line Processing Steps
        1. C.1.1. Quoting
        2. C.1.2. eval
    26. D. Revision Control
      1. D.1. CVS
        1. D.1.1. Pros
        2. D.1.2. Cons
        3. D.1.3. Example
        4. D.1.4. See Also
      2. D.2. Subversion
        1. D.2.1. Pros
        2. D.2.2. Cons
        3. D.2.3. Example
        4. D.2.4. See Also
      3. D.3. RCS
        1. D.3.1. Pros
        2. D.3.2. Cons
        3. D.3.3. Example
        4. D.3.4. Workon Script
        5. D.3.5. See Also
      4. D.4. Other
        1. D.4.1. Document Comparison
        2. D.4.2. Change Tracking and Versions
        3. D.4.3. Accessing These Features
    27. E. Building bash from Source
      1. E.1. Obtaining bash
      2. E.2. Unpacking the Archive
      3. E.3. What's in the Archive
        1. E.3.1. Documentation
        2. E.3.2. Configuring and Building bash
        3. E.3.3. Testing bash
        4. E.3.4. Potential Problems
        5. E.3.5. Installing bash as a Login Shell
        6. E.3.6. Examples
      4. E.4. Who Do I Turn To?
        1. E.4.1. Asking Questions
        2. E.4.2. Reporting Bugs
    28. Index
    29. About the Authors
    30. Colophon
    31. SPECIAL OFFER: Upgrade this ebook with O’Reilly