Books & Videos

Table of Contents

  1. Chapter 1 Beginning bash

    1. Why bash?

    2. The bash Shell

    3. Decoding the Prompt

    4. Showing Where You Are

    5. Finding and Running Commands

    6. Getting Information About Files

    7. Showing All Hidden (dot) Files in the Current Directory

    8. Using Shell Quoting

    9. Using or Replacing Built-ins and External Commands

    10. Determining If You Are Running Interactively

    11. Setting bash As Your Default Shell

    12. Getting bash for Linux

    13. Getting bash for xBSD

    14. Getting bash for Mac OS X

    15. Getting bash for Unix

    16. Getting bash for Windows

    17. Getting bash Without Getting bash

    18. Learning More About bash Documentation

  2. Chapter 2 Standard Output

    1. Writing Output to the Terminal/Window

    2. Writing Output but Preserving Spacing

    3. Writing Output with More Formatting Control

    4. Writing Output Without the Newline

    5. Saving Output from a Command

    6. Saving Output to Other Files

    7. Saving Output from the ls Command

    8. Sending Both Output and Error Messages to Different Files

    9. Sending Both Output and Error Messages to the Same File

    10. Appending Rather Than Clobbering Output

    11. Using Just the Beginning or End of a File

    12. Skipping a Header in a File

    13. Throwing Output Away

    14. Saving or Grouping Output from Several Commands

    15. Connecting Two Programs by Using Output As Input

    16. Saving a Copy of Output Even While Using It As Input

    17. Connecting Two Programs by Using Output As Arguments

    18. Using Multiple Redirects on One Line

    19. Saving Output When Redirect Doesn't Seem to Work

    20. Swapping STDERR and STDOUT

    21. Keeping Files Safe from Accidental Overwriting

    22. Clobbering a File on Purpose

  3. Chapter 3 Standard Input

    1. Getting Input from a File

    2. Keeping Your Data with Your Script

    3. Preventing Weird Behavior in a Here-Document

    4. Indenting Here-Documents

    5. Getting User Input

    6. Getting Yes or No Input

    7. Selecting from a List of Options

    8. Prompting for a Password

  4. Chapter 4 Executing Commands

    1. Running Any Executable

    2. Telling If a Command Succeeded or Not

    3. Running Several Commands in Sequence

    4. Running Several Commands All at Once

    5. Deciding Whether a Command Succeeds

    6. Using Fewer if Statements

    7. Running Long Jobs Unattended

    8. Displaying Error Messages When Failures Occur

    9. Running Commands from a Variable

    10. Running All Scripts in a Directory

  5. Chapter 5 Basic Scripting: Shell Variables

    1. Documenting Your Script

    2. Embedding Documentation in Shell Scripts

    3. Promoting Script Readability

    4. Separating Variable Names from Surrounding Text

    5. Exporting Variables

    6. Seeing All Variable Values

    7. Using Parameters in a Shell Script

    8. Looping Over Arguments Passed to a Script

    9. Handling Parameters with Blanks

    10. Handling Lists of Parameters with Blanks

    11. Counting Arguments

    12. Consuming Arguments

    13. Getting Default Values

    14. Setting Default Values

    15. Using null As a Valid Default Value

    16. Using More Than Just a Constant String for Default

    17. Giving an Error Message for Unset Parameters

    18. Changing Pieces of a String

    19. Using Array Variables

  6. Chapter 6 Shell Logic and Arithmetic

    1. Doing Arithmetic in Your Shell Script

    2. Branching on Conditions

    3. Testing for File Characteristics

    4. Testing for More Than One Thing

    5. Testing for String Characteristics

    6. Testing for Equal

    7. Testing with Pattern Matches

    8. Testing with Regular Expressions

    9. Changing Behavior with Redirections

    10. Looping for a While

    11. Looping with a read

    12. Looping with a Count

    13. Looping with Floating-Point Values

    14. Branching Many Ways

    15. Parsing Command-Line Arguments

    16. Creating Simple Menus

    17. Changing the Prompt on Simple Menus

    18. Creating a Simple RPN Calculator

    19. Creating a Command-Line Calculator

  7. Chapter 7 Intermediate Shell Tools I

    1. Sifting Through Files for a String

    2. Getting Just the Filename from a Search

    3. Getting a Simple True/False from a Search

    4. Searching for Text While Ignoring Case

    5. Doing a Search in a Pipeline

    6. Paring Down What the Search Finds

    7. Searching with More Complex Patterns

    8. Searching for an SSN

    9. Grepping Compressed Files

    10. Keeping Some Output, Discarding the Rest

    11. Keeping Only a Portion of a Line of Output

    12. Reversing the Words on Each Line

    13. Summing a List of Numbers

    14. Counting String Values

    15. Showing Data As a Quick and Easy Histogram

    16. Showing a Paragraph of Text After a Found Phrase

  8. Chapter 8 Intermediate Shell Tools II

    1. Sorting Your Output

    2. Sorting Numbers

    3. Sorting IP Addresses

    4. Cutting Out Parts of Your Output

    5. Removing Duplicate Lines

    6. Compressing Files

    7. Uncompressing Files

    8. Checking a tar Archive for Unique Directories

    9. Translating Characters

    10. Converting Uppercase to Lowercase

    11. Converting DOS Files to Linux Format

    12. Removing Smart Quotes

    13. Counting Lines, Words, or Characters in a File

    14. Rewrapping Paragraphs

    15. Doing More with less

  9. Chapter 9 Finding Files: find, locate, slocate

    1. Finding All Your MP3 Files

    2. Handling Filenames Containing Odd Characters

    3. Speeding Up Operations on Found Files

    4. Finding Files Across Symbolic Links

    5. Finding Files Irrespective of Case

    6. Finding Files by Date

    7. Finding Files by Type

    8. Finding Files by Size

    9. Finding Files by Content

    10. Finding Existing Files and Content Fast

    11. Finding a File Using a List of Possible Locations

  10. Chapter 10 Additional Features for Scripting

    1. "Daemon-izing" Your Script

    2. Reusing Code with Includes and Sourcing

    3. Using Configuration Files in a Script

    4. Defining Functions

    5. Using Functions: Parameters and Return Values

    6. Trapping Interrupts

    7. Redefining Commands with alias

    8. Avoiding Aliases, Functions

  11. Chapter 11 Working with Dates and Times

    1. Formatting Dates for Display

    2. Supplying a Default Date

    3. Automating Date Ranges

    4. Converting Dates and Times to Epoch Seconds

    5. Converting Epoch Seconds to Dates and Times

    6. Getting Yesterday or Tomorrow with Perl

    7. Figuring Out Date and Time Arithmetic

    8. Handling Time Zones, Daylight Saving Time, and Leap Years

    9. Using date and cron to Run a Script on the Nth Day

  12. Chapter 12 End-User Tasks As Shell Scripts

    1. Starting Simple by Printing Dashes

    2. Viewing Photos in an Album

    3. Loading Your MP3 Player

    4. Burning a CD

    5. Comparing Two Documents

  13. Chapter 13 Parsing and Similar Tasks

    1. Parsing Arguments for Your Shell Script

    2. Parsing Arguments with Your Own Error Messages

    3. Parsing Some HTML

    4. Parsing Output into an Array

    5. Parsing Output with a Function Call

    6. Parsing Text with a read Statement

    7. Parsing with read into an Array

    8. Getting Your Plurals Right

    9. Taking It One Character at a Time

    10. Cleaning Up an SVN Source Tree

    11. Setting Up a Database with MySQL

    12. Isolating Specific Fields in Data

    13. Updating Specific Fields in Data Files

    14. Trimming Whitespace

    15. Compressing Whitespace

    16. Processing Fixed-Length Records

    17. Processing Files with No Line Breaks

    18. Converting a Data File to CSV

    19. Parsing a CSV Data File

  14. Chapter 14 Writing Secure Shell Scripts

    1. Avoiding Common Security Problems

    2. Avoiding Interpreter Spoofing

    3. Setting a Secure $PATH

    4. Clearing All Aliases

    5. Clearing the Command Hash

    6. Preventing Core Dumps

    7. Setting a Secure $IFS

    8. Setting a Secure umask

    9. Finding World-Writable Directories in Your $PATH

    10. Adding the Current Directory to the $PATH

    11. Using Secure Temporary Files

    12. Validating Input

    13. Setting Permissions

    14. Leaking Passwords into the Process List

    15. Writing setuid or setgid Scripts

    16. Restricting Guest Users

    17. Using chroot Jails

    18. Running As a Non-root User

    19. Using sudo More Securely

    20. Using Passwords in Scripts

    21. Using SSH Without a Password

    22. Restricting SSH Commands

    23. Disconnecting Inactive Sessions

  15. Chapter 15 Advanced Scripting

    1. Finding bash Portably for #!

    2. Setting a POSIX $PATH

    3. Developing Portable Shell Scripts

    4. Testing Scripts in VMware

    5. Using for Loops Portably

    6. Using echo Portably

    7. Splitting Output Only When Necessary

    8. Viewing Output in Hex

    9. Using bash Net-Redirection

    10. Finding My IP Address

    11. Getting Input from Another Machine

    12. Redirecting Output for the Life of a Script

    13. Working Around "argument list too long" Errors

    14. Logging to syslog from Your Script

    15. Sending Email from Your Script

    16. Automating a Process Using Phases

  16. Chapter 16 Configuring and Customizing bash

    1. bash Startup Options

    2. Customizing Your Prompt

    3. Change Your $PATH Permanently

    4. Change Your $PATH Temporarily

    5. Setting Your $CDPATH

    6. Shortening or Changing Command Names

    7. Adjusting Shell Behavior and Environment

    8. Adjusting readline Behavior Using .inputrc

    9. Keeping a Private Stash of Utilities by Adding ~/bin

    10. Using Secondary Prompts: $PS2, $PS3, $PS4

    11. Synchronizing Shell History Between Sessions

    12. Setting Shell History Options

    13. Creating a Better cd Command

    14. Creating and Changing into a New Directory in One Step

    15. Getting to the Bottom of Things

    16. Adding New Features to bash Using Loadable Built-ins

    17. Improving Programmable Completion

    18. Using Initialization Files Correctly

    19. Creating Self-Contained, Portable RC Files

    20. Getting Started with a Custom Configuration

  17. Chapter 17 Housekeeping and Administrative Tasks

    1. Renaming Many Files

    2. Using GNU Texinfo and Info on Linux

    3. Unzipping Many ZIP Files

    4. Recovering Disconnected Sessions Using screen

    5. Sharing a Single bash Session

    6. Logging an Entire Session or Batch Job

    7. Clearing the Screen When You Log Out

    8. Capturing File Metadata for Recovery

    9. Creating an Index of Many Files

    10. Using diff and patch

    11. Counting Differences in Files

    12. Removing or Renaming Files Named with Special Characters

    13. Prepending Data to a File

    14. Editing a File in Place

    15. Using sudo on a Group of Commands

    16. Finding Lines in One File But Not in the Other

    17. Keeping the Most Recent N Objects

    18. Grepping ps Output Without Also Getting the grep Process Itself

    19. Finding Out Whether a Process Is Running

    20. Adding a Prefix or Suffix to Output

    21. Numbering Lines

    22. Writing Sequences

    23. Emulating the DOS Pause Command

    24. Commifying Numbers

  18. Chapter 18 Working Faster by Typing Less

    1. Moving Quickly Among Arbitrary Directories

    2. Repeating the Last Command

    3. Running Almost the Same Command

    4. Quick Substitution

    5. Reusing Arguments

    6. Finishing Names for You

    7. Playing It Safe

  19. Chapter 19 Tips and Traps: Common Goofs for Novices

    1. Forgetting to Set Execute Permissions

    2. Fixing "No such file or directory" Errors

    3. Forgetting That the Current Directory Is Not in the $PATH

    4. Naming Your Script Test

    5. Expecting to Change Exported Variables

    6. Forgetting Quotes Leads to "command not found" on Assignments

    7. Forgetting That Pattern Matching Alphabetizes

    8. Forgetting That Pipelines Make Subshells

    9. Making Your Terminal Sane Again

    10. Deleting Files Using an Empty Variable

    11. Seeing Odd Behavior from printf

    12. Testing bash Script Syntax

    13. Debugging Scripts

    14. Avoiding "command not found" When Using Functions

    15. Confusing Shell Wildcards and Regular Expressions

  1. Appendix A Reference Lists

    1. bash Invocation

    2. Prompt String Customizations

    3. ANSI Color Escape Sequences

    4. Built-in Commands and Reserved Words

    5. Built-in Shell Variables

    6. set Options

    7. shopt options

    8. Adjusting Shell Behavior Using set, shopt, and Environment Variables

    9. Test Operators

    10. I/O Redirection

    11. echo Options and Escape Sequences

    12. printf

    13. Date and Time String Formatting with strftime

    14. Pattern-Matching Characters

    15. extglob Extended Pattern-Matching Operators

    16. tr Escape Sequences

    17. Readline Init File Syntax

    18. emacs Mode Commands

    19. vi Control Mode Commands

    20. Table of ASCII Values

  2. Appendix B Examples Included with bash

    1. Startup-Files Directory Examples

  3. Appendix C Command-Line Processing

    1. Command-Line Processing Steps

  4. Appendix D Revision Control

    1. CVS

    2. Subversion

    3. RCS

    4. Other

  5. Appendix E Building bash from Source

    1. Obtaining bash

    2. Unpacking the Archive

    3. What's in the Archive

    4. Who Do I Turn To?

  6. Colophon