You are previewing Learning Shell Scripting with Zsh.
O'Reilly logo
Learning Shell Scripting with Zsh

Book Description

Your one-stop guide to reading, writing, and debugging simple and complex Z shell scripts

In Detail

Zsh has become incredibly popular in recent times and reasonably so; the shell boasts some really great features such as command completion, filename generation, and history sharing among instances of the shell. Learning to use them to your advantage will prove to be really valuable and will save you from lots of tedious and overly-complex tasks.

This hands-on guide will show you how to configure and use zsh for work and daily tasks. It provides a clear introduction to the more powerful features of the shell such as globbing and completion. This book will help you take advantage of the real power behind the UNIX shell on both desktops and servers through real-world examples.

This book will help you understand the features of zsh and make it one of the most valuable assets in your toolbox. It will teach you how to use the shell history to look up and edit previously typed entries and take advantage of the line-editor module to speed up your typing and editing of commands. You will be able to create your own completion functions and ensure you never mistype a command or have to look at the manpages again.

You will learn how to define your own aliases and learn about filename generation so you can do more by typing even less. You will also discover the essentials of zsh and go deeper with its more advanced features. When you are done with this book, your time with the command line will be much more enjoyable and productive.

What You Will Learn

  • Set up and configure the advanced aspects of zsh such as process and parameter substitution, running on restricted functionality mode, and emulating other shells, for example, ksh and Bourne
  • Customize the shell prompt to display the information you need
  • Work with the line-editor module to type less and do more
  • Use filename generation, also known as globbing, to work with files and folders
  • Discover programmable completion and never mistype a command or its options again
  • Tame the shell history and use it simultaneously on multiple shells with just a few keystrokes
  • Expand on zsh’s built-in modules and functionality by creating your own functions
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning Shell Scripting with Zsh
      1. Table of Contents
      2. Learning Shell Scripting with Zsh
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Started
        1. Installing zsh
          1. Installing on Linux
          2. Installing on OS X
          3. Compiling from source
        2. First run
          1. Making zsh your login shell
          2. Shell options
          3. The startup files
        3. The shell prompt
          1. The prompt command
          2. Customizing the prompt
          3. Using escape sequences
            1. Shell state options
            2. Login information options
            3. Directory options
            4. Date and time options
            5. Text formatting options
          4. Conditional expressions
          5. Putting it all together
        4. Summary
      9. 2. Alias and History
        1. Working with aliases
          1. Quoting characters
          2. Single and double quoting aliases
          3. Global aliases
          4. Hashes
          5. Putting it all together
        2. Expansion
          1. Parameter expansion
          2. Command substitution
          3. Arithmetic expansion
          4. Brace expansion
        3. Working with history
          1. History expansion
          2. History substitution
          3. More useful options
        4. Summary
      10. 3. Advanced Editing
        1. Zsh line editor
          1. Getting to know ZLE
          2. Working with keymaps
          3. Basic editing
            1. Going back and forth with words
            2. Yanking and transposing text
          4. Revisiting history
        2. Advanced editing
          1. ZLE-related options
          2. Defining your own keymaps
        3. Don't call them widgets
          1. Defining your own widgets
            1. Special variables
          2. Your first function
        4. Working with regions
          1. Multiline editing
          2. Putting it all together
        5. Summary
      11. 4. Globbing
        1. Quoting your strings
          1. Double quotes
        2. Getting started with Globbing
          1. Globbing with the stars
          2. Questions for any single character
          3. Brackets for a sequence of characters
          4. Using safer ranges on your scripts
            1. Avoiding characters
          5. Handling mismatches
        3. Extended Globbing
          1. Special patterns
            1. Recursive searching
            2. Alternate patterns
            3. Numeric ranges
            4. Revisiting the caret operator
            5. The tilde operator
          2. Glob qualifiers
            1. Timestamp qualifiers
            2. File size qualifiers
        4. The zmv function
        5. Summary
      12. 5. Completion
        1. Getting started with completion
          1. Getting assertive with zstyle
        2. Command correction
          1. Completers
          2. Ignoring matches
        3. Function definitions
          1. The path of the function
        4. Summary
      13. 6. Tips and Tricks
        1. Main resources
        2. Helping tips
          1. Directory substitution
          2. Magic space
          3. Random numbers
          4. zcalc
          5. Change and list directory contents
          6. Finding your path through commands
        3. Other projects
          1. zsh-lovers
          2. zsh-users
          3. oh-my-zsh
          4. Prezto
          5. Explain Shell
          6. Your dotfiles
        4. Summary
      14. Index