0%

Shell scripts are everywhere, especially those written in bash compatible syntax, and it's extremely useful to be able to understand and write them, but they can be complex and obscure. Complexity is the enemy of security, but it's also the enemy of readability and understanding. With this practical book, you'll learn how to decipher old bash code and write new code that's as clear and readable as possible. Your future you will thank you.

Authors Carl Albing and JP Vossen show you how to use the power and flexibility of the shell to your advantage. You'll learn how to read and write scripts like an expert, so that you can:

  • Write useful, flexible, and readable bash code...with style
  • Decode bash code such as ${MAKEMELC,,} and ${PATHNAME##*/}
  • Save time and ensure consistency when automating tasks
  • Amaze and impress colleagues with bash idioms
  • Discover how bash idioms can make your code clean and concise

Table of Contents

  1. Preface
    1. Running bash
    2. Revision Control
    3. Hello World
    4. Conventions Used in This Book
    5. Using Code Examples
    6. O’Reilly Online Learning
    7. How to Contact Us
    8. Acknowledgments
  2. 1. A Big “If” Idiom
    1. The Big “if”
    2. Or ELSE…
    3. More Than One
    4. More Than One Again
    5. Style and Readability: When To Use Which Form of If
    6. Summary
  3. 2. Looping Lingo
    1. Looping constructs
    2. Explicit Values
    3. Similar to Python
    4. Quotes and Blanks
    5. Style and Readability
    6. Summary
  4. 3. Expressions and Arithmetic
    1. Arithmetic
    2. No Parentheses Needed
    3. Compound Commands
    4. Style and Readability
    5. Summary
  5. 4. List and Hash Handling
    1. Commonalities
    2. Lists
    3. Hashes
    4. A simple word count example
    5. Style and Readability
    6. Summary
  6. 5. Developing your Style Guide
    1. Readability
    2. Comments
    3. Names
    4. Functions
    5. Quoting
    6. Layout
    7. Syntax
    8. Other
    9. Script Template
    10. Other Style Guides
    11. Bash Linter
    12. Summary
  7. A. Bash Idioms Style Guide
    1. Readability
    2. Comments
    3. Names
    4. Functions
    5. Quoting
    6. Layout
    7. Syntax
    8. Other
    9. Script Template
  8. Index